So as newbie to Phoenix I have been playing around and reading a lot and there seems to be three places with dealing with Associations in Phoenix, but I am not sure which is best practice:
- In the Changeset in the schema file. I think this works best for certain types of association, but others such as M2M put_assoc and cast_assoc don’t seem to capture every case easily. It doesn’t seem correct to me to put it in the Changeset, but I am not an experienced Phoenix developer.
- In the Controller, such as web controller. I have seen many examples of others doing this, it seems like the easiest place but seems like it’s not as reusable.
- In the Context (such as
create_todo
) so that on creating or updating etc, could deal with the association.
I guess the answer is depends, but in my particular use-case with several many_to_many associations I am leaning towards putting somethings in the Context files, and having separate context for a join_through Table to make associations. Is this a bad idea?
Thanks in advance