Open RobStallion opened 5 years ago
It appears that the reason for the error is because the user changeset
function does not return an error when there is a duplicate email hash. That step looks like it is being done in alog
.
Alog must have a function for checking unique constraints, but this step must be missed when the table is an association.
As there cannot be a unique index in alog (as many rows can relate to one user for example) it looks like alog is doing a version of this logic here.
I don't fully understand this function at the moment but it appears that it gets a list of constraints from changeset and reduces them, returning a changeset with errors added as needed. However it does not appear to work for associations.
I will take a deeper look at this but from what I have seen so far it appears that associations in changesets, are just a list of changesets themselves (at least in the case of a many to many association). This should mean that this function can be called recursively on the nested list of changeset.
I am not sure how the errors in nested changeset will effect the top level changeset at the moment.
I am currently using alog in another project where two tables are being updated at the same time.
The
venue
table has amany to many
association with theusers
table. When a user of the site creates a newvenue
they can also create a newuser
at the same time.However, for some reason the user changeset function is not working as expected here. It is allowing multiple users with the same email address to be created.
This does not happen when you try to create a user on their own (e.g. Call the
User.insert
function directly with auser changeset
)