How add and remove items from N:M relationship using webratio?

03 Sep '14, 02:54 PM
3,158 Views
Forum Forum Starter - Level 1

Hi, 

How can I add and remove objects in a relationship N: M. 
For example, the following model: Music and listeners. 
A song may have been heard by one or more persons, 
well as a person may have heard one or more songs. 

Considering that is a page displaying information of a song and want to put a button to add the music to the user list. 
How to model the action of this flow? 

A solution that was used to get the list of IDs of the songs already in relationship and groovy code via add the desired item. 
And with the new list of IDs, set up a playlist on user relationship and the music. It worked, but it was not an interesting solution. 

There is a way to do this at the level of abstraction of the model using both webratio to insert as to remove objects from a relationship?

Thanks.

 
x 0
Follow
Answer Answer at this question and get points!
Forum Hero - Level 9

Hi Gilvan, you can use a selector component with the music entity and a relationship (user - music) and a key condition (oid music) send the params in the bing and compare the result with a is not null component or switch component(with the Data size return)

   
x 2
Forum Hero - Level 9

Hi Gilvan,

You can use the connect component, I send the article for you know how can use this component.

http://www.webratio.com/learn/learningobject/Connect-Unit?link=oln72ae.redirect&nav=14#!ajax=true

http://www.webratio.com/learn/learningobject/Disconnect-Unit?link=oln72ae.redirect&nav=14#!ajax=true

http://www.webratio.com/learn/learningobject/Reconnect-Unit?link=oln72ae.redirect&nav=14#!ajax=true

with the connect component you can add the relationship when the user add a new music to the list. and if you want delete a relationship you can use the disconnect component.

 
x 2
Forum Starter - Level 1

Thanks Veronica I did not know this component.

I'll learn reading the article you send me.

Thanks a lot.

 
x 0
Forum Starter - Level 1

One more question. 
In the same model, musics and users, how do I know if a song is already present on the user list?

 
x 0
Answer at this question and get points!

Related questions