activerecord-import
activerecord-import copied to clipboard
belongs_to isn't processed in import
I seems that belongs_to
relation isn't proceeded by import during commit, my log shows that import inserts the only has_one/many
relations. How can it be fixed?
Is there a reason why you can't start the import from the model associated using belongs_to
, basically going up one more level?
@jkowens yes, because that models isn't at the top of the import trees. And I start the proceeding from a models, which is on the top of the import tree.
@jkowens example: Tags has_many Posts, Posts belongs_to Types, i need save tags with posts and types
Gotcha. Unfortunately I think "recursive" import will have to be limited to has_many associations, otherwise we'd end up with endless cycles.
So in the example above, types would have to be imported first and then tags with posts.
@jkowens If you will properly process the has_many/belongs to pairs it will not lead to recursion, because it will not walk over already proceeded relations,
That's true, I suppose a hash with keys for each class could be added that holds all imported associations. Then when selecting associated models to import we could first check to see if it exists in the array for that class in the processed hash.
I assume the memory overhead wouldn't be significant. Do you think you'd be able to work on a patch for this feature?
It would also be helpful if you could provide some benchmarks for recursive imports with just has_many associations before and after the change.
That way it would be easier to determine if the benefits outweigh the costs (performance, complexity, etc).
Importing belongs_to
associations is still not supported recursively, but here is an example how to possibly handle such a situation for now:
See this thread: https://github.com/zdennis/activerecord-import/issues/402#issuecomment-328375171