With this, the coaster_id field in the Incarnations table is filled in but not the coaster_versions_id field. Any idea how I can get this field to fill in?
Basically I run an import from a CSV which creates Coasters. Before creating the new Coaster, it checks if a certain attribute of the one it is to create already exists (it’s an id type attribute but not a unique id, for another purpose). If it already exists then it adds it as normal but should add a record to the Incarnations table.
So if a record does exist I store that as c and the newly created Coaster as coaster so I then run:
coaster.incarnations.create!(coaster_version: c) – See the difference from my OP?
But the problem is that the coaster_version_id does not get filled in. It should be filled in with the id of c.
Just come back to look at this and can’t see how this would work. Maybe I am going about this the wrong way.
Basically if a record that I am importing has a certain attribute id the same as an already existing record then I want to the new record to relate to the first one via this relationship. How would this be accomplished?
if you have a coaster with an id and a coaster_version with an id (meaning, they’ve both been persisted), then coaster.coaster_versions << coaster_version will create the join table entry (incantation) This is how AR Associations work, AFAIK.