The correct way to "link" associations in Ecto when you only have an id integer

I understand that there is a difference between put_assoc and cast_assoc. (one being the things you want to link already exist and the other is the I’d like to create two things at once). I also understand that you need to take into consideration of the association’s on_delete and on_replace behaviors when using put/cast_assoc

My question is what if I already have two things and all I want to do is link them but I dont want to preload the thing I’m linking (IE I only have its ID value) ?

Q: What is the proper way of linking an association if all you have is an id?

Just set the foreign key directly, it’ll be something like blah_id if the association is named blah. It’s just like any other field. :slight_smile:

2 Likes

Could you make this any harder, jeez. :rofl:?

1 Like