<composite alias="Favorites" class="Favorites" local="id" foreign="user_id" cardinality="many" owner="local" />
<object class="Game" table="games" extends="xPDOObject">
<field key="id" dbtype="int" precision="10" phptype="integer" null="false" index="pk" generated="native" />
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<composite alias="Favorites" class="Favorites" local="id" foreign="game_id" cardinality="many" owner="local" />
</object>
<object class="Favorites" table="favorites" extends="xPDOObject">
<field key="id" dbtype="int" precision="10" phptype="integer" null="false" index="pk" generated="native" />
<field key="user_id" dbtype="int" precision="10" phptype="integer" null="false" index="pk" generated="native" />
<field key="game_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="time" dbtype="datetime" phptype="datetime" null="true"/>
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<aggregate alias="modUser" class="modUser" local="user_id" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="Game" class="Game" local="game_id" foreign="id" cardinality="one" owner="foreign" />
</object>
This question has been answered by BobRay. See the first response.
$myUser->getMany('Favorites');
<object class="Game" table="games" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<composite alias="Favorites" class="Favorites" local="id" foreign="game_id" cardinality="many" owner="local" />
</object>
<object class="Favorites" table="favorites" extends="xPDOSimpleObject">
<field key="user_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="game_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="time" dbtype="datetime" phptype="datetime" null="true"/>
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<aggregate alias="User" class="modUser" local="user_id" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="Game" class="Game" local="game_id" foreign="id" cardinality="one" owner="foreign" />
</object>
<object class="extUser" extends="modUser"> <composite alias="Favorites" class="Favorites" local="id" foreign="user_id" cardinality="many" owner="local" /> </object>
<object class="Favorites" table="favorites" extends="xPDOObject">
<field key="id" dbtype="int" precision="10" phptype="integer" null="false" index="pk" generated="native" />
<field key="user_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="game_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="time" dbtype="datetime" phptype="datetime" null="true"/>
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="user_id" collation="A" null="false" />
<column key="game_id" collation="A" null="false" />
</index>
<aggregate alias="User" class="modUser" local="user_id" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="Game" class="Game" local="game_id" foreign="id" cardinality="one" owner="foreign" />
</object>
Looks good from 10,000ft. You don't need the id column in Favorites if user_id+game_id is the Primary Key.
$userfav = $this->modx->newObject('Favorites',array(
'game_id' => $gameid,
'user_id' => $userid
));
$userfav->save();
// Games
<object class="Game" table="games" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<composite alias="Favorites" class="Favorites" local="id" foreign="game_id" cardinality="many" owner="local" />
</object>
// Extending modUser
<object class="extUser" extends="modUser">
<composite alias="Favorites" class="Favorites" local="id" foreign="user_id" cardinality="many" owner="local" />
</object>
// Favorites
<object class="Favorites" table="favorites" extends="xPDOObject">
<field key="user_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="game_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="time" dbtype="datetime" phptype="datetime" null="true"/>
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="user_id" collation="A" null="false" />
<column key="game_id" collation="A" null="false" />
</index>
<aggregate alias="User" class="extUser" local="user_id" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="Game" class="Game" local="game_id" foreign="id" cardinality="one" owner="foreign" />
</object>
Looks perfect to me.
[2013-09-18 08:53:57] (ERROR @ /assets/components/games/connector.php) Error removing dependent object: Array
(
[user_id] => 1
[game_id] => 266
[time] => 2013-09-18 08:53:38
)Quote from: BobRay at Sep 17, 2013, 03:40 PMLooks perfect to me.
It saves the value in the database, however when I delete a user or a game, the relational favorites are not getting deleted.
[2013-09-18 08:53:57] (ERROR @ /assets/components/games/connector.php) Error removing dependent object: Array ( [user_id] => 1 [game_id] => 266 [time] => 2013-09-18 08:53:38 )
class GameRemoveProcessor extends modObjectRemoveProcessor {
public $classKey = 'Game';
public $languageTopics = array('games:default');
public $objectType = 'games.game';
}
return 'GameRemoveProcessor';Quote from: km88 at Sep 18, 2013, 01:58 AMQuote from: BobRay at Sep 17, 2013, 03:40 PMLooks perfect to me.
It saves the value in the database, however when I delete a user or a game, the relational favorites are not getting deleted.
[2013-09-18 08:53:57] (ERROR @ /assets/components/games/connector.php) Error removing dependent object: Array ( [user_id] => 1 [game_id] => 266 [time] => 2013-09-18 08:53:38 )
How are you deleting the user/game records?