Need to use association data in a changeset

14 views
Skip to first unread message

Idean Labib

unread,
Jun 24, 2017, 3:26:09 AM6/24/17
to phoenix-talk
I just found out about this group while trying to find a solution to a problem my group is facing.

Our issue is that one of our model's changeset validations is dependent on an attribute of a child association. We should not be able to update the record if a boolean value is set to true in the child association.

However, we are not guaranteed that the changeset will always be called with a struct that preloads the association that we need. We want to avoid making a Repo.preload call in the model as much as possible because of separation of concerns, and we know this may set a precedent for poor coding practices in the future.

We have considered checking if the association is preloaded in the changeset, and throwing an error if it is not. However, we want to avoid this solution as much as possible.

I would greatly appreciate it if anybody knows of a cleaner solution for us to use.

Reply all
Reply to author
Forward
0 new messages