Jump to content


Photo

Many to Many Relationship with itself


  • Please log in to reply
4 replies to this topic

#1 sanbrar

sanbrar

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 21 June 2012 - 02:40 PM

I have to need to setup many to many relationship for a module with itself. Relationship in the model is defined as follow:

'c_catalogues'		 => array(RedBeanModel::MANY_MANY,			 'C_catalogue'),

Table to maintain many to many relationship is created in the database "c_catalogue_c_catalogue", with columns id, c_catalogue_id, and c_catalogue2_id.


Is there any other relationship I should be using?

Thanks.

#2 Jason

Jason

    Administrator

  • Administrators
  • 716 posts
  • LocationChicago

Posted 21 June 2012 - 04:22 PM

I have to need to setup many to many relationship for a module with itself. Relationship in the model is defined as follow:

'c_catalogues'		 => array(RedBeanModel::MANY_MANY,			 'C_catalogue'),

Table to maintain many to many relationship is created in the database "c_catalogue_c_catalogue", with columns id, c_catalogue_id, and c_catalogue2_id.


Is there any other relationship I should be using?

Thanks.

Are you sure you want a many-to-many relationship? Can you explain the use case more?

Jason Green
Zurmo Team
Need support? Upgrade now


#3 sanbrar

sanbrar

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 21 June 2012 - 04:39 PM

Use Case:

Lets suppose we have Catalogue items A to Z.

Item A is made up of items J,K,L,M
Item B is made up of items L,M,N,O,P


When user looks at item A user should be able to see all items it's made up off. In this case A contains J,K,L, and M

When user looks at item M user should be able to see all items (if any) it belongs to. In this case M is part of A, and B


Now that I think about it, it would nice to distinguish between all the items an item is made up of vs all items an item is part of.

#4 sanbrar

sanbrar

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 21 June 2012 - 09:53 PM

I wasn't able to get many to many for same entity work. Work around was to create intermediate entity.

Created two different related views to achieve the functionality I needed. It's little inconvenient that user has to create a record in this intermediate entity rather than app doing it for the user but it works.

#5 Jason

Jason

    Administrator

  • Administrators
  • 716 posts
  • LocationChicago

Posted 25 June 2012 - 03:36 PM

Ok, We will have to work on a better solution for this

Jason Green
Zurmo Team
Need support? Upgrade now





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users