Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate using given models instead of re-initializing ones #118

Closed
wants to merge 1 commit into from

Conversation

giladas
Copy link

@giladas giladas commented Nov 24, 2013

Hi,
when using import with models and validations are enabled, the models are converted to arrays, re-initialized and then the validation process is taking place. It's not necessary to re-initialize the models since they were given as parameters, and it took more time than the actual db insert.

@oded-simplee
Copy link

Also, if some of the validations work on associations, they will re-load the association instead of using the one in the given model, thus making N queries when you wanted just 1 INSERT.

@@ -216,7 +216,25 @@ def import( *args )
end

return_obj = if is_validating
import_with_validations( column_names, array_of_attributes, options )
if models
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the idea @giladas, I was thinking about submitting a pull request for exactly this a few days ago.

Since this is more or less the same validation logic as in import_with_validations, perhaps there is a way we can DRY the logic up?

@jkowens
Copy link
Collaborator

jkowens commented Jun 23, 2016

This has been implemented by #266.

@jkowens jkowens closed this Oct 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants