You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This solution works if you have a foreign key to relate your data. However, if I do not have foreign keys on the Model I'm importing to(in my case User), I cannot use this method. It relies on being able to rename the field, to the foreign key and replacing that value.
I see the problem as coming down to the fact that:
the CSV is accessed in before_batch _import hook
the newly created models can only be modified(associated with other records) in the after_batch_import hook,
There is no way to transfer this information from the before/import block other than to use headers_rewrites ( and thus the renaming of an input to a different field on your user model)
I came up with a solution in which the batch_size is set to 1, and instance variables carry over the association information to the after block for the associations to be made. This doesn't seem ideal because I'm forcing the batch to be 1 record and not leveraging any of the bulk import functionality.
What I would like to be able to do is to use information on the csv to make associations in the after_batch_import block. I would like to be able to loop through the csv lines, look up the record belonging to that line, and associate the user using that information.
The batch_slice method would need to prevent the use of these columns in the before block, but also allow them to be accessed in the after_batch_import block.
Does this seem like a plausible solution? Is there a better work around to solve this problem?
The text was updated successfully, but these errors were encountered:
While importing a CSV to create users, I'd like to add associations to records on other models. I have looked at this solution:
#68
This solution works if you have a foreign key to relate your data. However, if I do not have foreign keys on the Model I'm importing to(in my case User), I cannot use this method. It relies on being able to rename the field, to the foreign key and replacing that value.
I see the problem as coming down to the fact that:
I came up with a solution in which the batch_size is set to 1, and instance variables carry over the association information to the after block for the associations to be made. This doesn't seem ideal because I'm forcing the batch to be 1 record and not leveraging any of the bulk import functionality.
What I would like to be able to do is to use information on the csv to make associations in the after_batch_import block. I would like to be able to loop through the csv lines, look up the record belonging to that line, and associate the user using that information.
The batch_slice method would need to prevent the use of these columns in the before block, but also allow them to be accessed in the after_batch_import block.
Does this seem like a plausible solution? Is there a better work around to solve this problem?
The text was updated successfully, but these errors were encountered: