Many to Many relationship

Hi. Is there a simple way to create many to many relationships between tables in Backendless? Or do i have to use a third table to achieve this?

No, you do not need to create a separate table. Just link the entities together and they will automatically be many-to-many.

Hi Mark. You mean to create one to many relationship in table A, and one to many in table B?

Yes, for example consider the following entities (not the best data modeling, but gets the point across )) ):

Parent

  • name
  • age
  • children << collection of children

Child

  • name
  • age
  • parents << collection of parents

As you can see the relationship between Parent and Child is many-to-many. One parent could have many children, and a child may have more than one parent.

Regards,
Mark

Good afternoon Mark, if need add a property name “active”. If not in the middle table, where would it be? Thanks.

Hi @mark-piller can you explain more please, I don’t understand when you say just link the two together. I appreciate this reply may have been prior to the visual modeler… so how do I create a relationship of many-to-many please?

Hi Graham,

Could you please describe the relationship you are trying to model? What are the entity/table names? What would be the name of the column?

Regards,
Mark

Hi @mark-piller ,

I intend to build a system that has many Customers, each with one or more Apps. Each Customer may have many Locations (addresses).

Each of the Customer’s Apps may be associated to many of the Customer’s Locations.

So I’ve got:

Customer table to App table (one-to-many)
Customer table to Locations (one-to-many)

Location table to App table (many-to-many)?

The column name would be Location in the App Table.

Is the last relationship unnecessary as the other two are in place and therefore it’s inherited?

Hi, @Graham_Reddie

You need to make a relation column between Apps and Locations tables. Because without it you can not get information from Apps table to Location table and vice versa.

Regards,
Marina

Hi @Marina.Kan than you for your reply.

I appreciate that I need to setup a relationship but as I said in the beginning I’m wanting to create a many-to-many relationship, so do you know how that is achieved? As you can see Im familiar with setting up one-to-one and one-to-many relationships just not many-to-many ones.

Hi Graham,

if the App is related to Location through a Customer, I do not think an explicit relationship between App and Location is needed. Without a Customer in the middle, that relationship does not make sense. Maybe I am missing something…

Regards,
Mark