Redbean remove entries from sharedList

526 views Asked by At

I am using RedBean and i want to remove the relationships existing at sharedList. Right now i am using

$bean->sharedList = array();
R::store($bean);

But it does not work. Any suggestions?

2

There are 2 answers

0
Ashish Nayyar On

As per RedBean documentation

A shared list contains beans that may be associated with more than just one other bean (many-to-many relation).

list($vase, $lamp) = R::dispense('product', 2);

$tag = R::dispense( 'tag' );
$tag->name = 'Art Deco';

//creates product_tag table!
$vase->sharedTagList[] = $tag;
$lamp->sharedTagList[] = $tag;
R::storeAll( [$vase, $lamp] );

In your code you are not sharing it with any other list. Would you share what exactly you are trying to achieve.

0
charliefortune On

The property containing the collection needs to have the name of a bean type in it;

e.g.

$class->sharedStudent = array();
R::store($class);

This will remove the relationship between the $class bean and any student beans it was previously related to. The student beans will not be deleted however.

Your example would only work if the shared bean type was of type 'list' (which I doubt it is.)

Incidentally, you don't need to add 'List' onto the end of a shared collection any more. This was deprecated a few versions back, near the beginning of Redbean 4 I believe.