Hi!

I'm creating a mobile app, in which there is a user directory and I want users to be able to add other users as "favourites".

My data model looks like this:

My goal is, to create an action to change "FavId" to set the ID of the user that become "favorite" on the screen where the user sets the other user as favorite.

This doesn't work, I get an error message "Upgrade Error Could not create foreign key constraint. This may have happened because there are 'VetId' values of entity 'MyAssignedVet' with no corresponding value in entity 'User', or attribute 'VetId' of entity 'MyAssignedVet' is creating a circular dependency between entities. Check the Error Log for more information."

Conceptually, what would be the correct way to go about this so that each logged user can have its own favorite users list?

Thank you

Solution

Hi Nicola,


The data model which you defined can only hold a single Favorite user because it's One-To-One Relationship.

Below data model will help you to store -- A single user can select/store Multiple Favorite user 



Adding to that, define Unique index on FavoriteUser Entity attributes as mentioned below to avoid duplicate User-Favorite user record in FavoriteUser Entity.


Hope this helps you!


Regards,

Benjith Sam

Solution

Hi Nicola,

Please try to follow the below pattern:

This might helps you in achieving your goal.

Regards,

Manish Jawla

Hi!

Thank you for both replies.

I have changed the model to follow your instructions but am still getting the same error: "Upgrade Error Could not create foreign key constraint. This may have happened because there are 'FavUserId' values of entity 'Myfavourite' with no corresponding value in entity 'User', or attribute 'FavUserId' of entity 'Myfavourite' is creating a circular dependency between entities. Check the Error Log for more information."

Where do you think this could come from?

Hi, nicola.

Benjth and Manish already give you the proper way to model your data to allow a 1:many relationship, that seems what you want.

Let me just talk about the error, that does not seem related to your data model question,  

"Upgrade Error Could not create foreign key constraint. This may have happened because there are 'VetId' values of entity 'MyAssignedVet' with no corresponding value in entity 'User', or attribute 'VetId' of entity 'MyAssignedVet' is creating a circular dependency between entities. Check the Error Log for more information."

Most probably you are trying to change the Mandatory property of the VetId (that is probably a User Identifier), to yes, but you already have records in the entity where this value is not set, violating the constraint (Mandatory). 

Another possibility is that VetId is the Primary Key of the MyAssignedVet, and you are trying to change its data type to a User Identifier AFTER you already have published the entity previously. After publishing it is not possible to change an Entity Identifier data type. 

Cheers.

P.S. About the new error, you can't change the entity identifier after the entity is published. If this is the case, you need to recreate the entity (copy/paste, delete the old, change whatever you want to change and then publish).

Also, having both FK's pointing to the same entity with a Delete Rule set to DELETE probably is also a problem...
Try setting one of it to IGNORE instead, if the error persists in a new entity. 

Thank you for clarifying, I understand now. Deleting and recreating the Entity did the trick. Thanks all for your help!