Hi, following case:
I have a Class, that is related as a many_many with two other classes. One of the many_many relations has an extra field for sorting.
Here is a simple Example in code:
<code>
class MyObject extends DataObject {
private static $db = array(
'Title' => 'Text',
'Active' => 'Boolean'
);
private static $belongs_many_many {
'Categories' => 'Category',
'Tags' => 'Tag'
}
}
class Tag extends DataObject {
private static $db = array(
'Title' => 'Text'
);
private static $many_many {
'MyObjects' => 'MyObject'
}
}
class Category extends DataObject {
private static $db = array(
'Title' => 'Text'
);
private static $many_many {
'MyObjects' => 'MyObject'
}
private static $many_many_extraFields=array(
'MyObjects'=>array(
'CategorySortOrder'=>'Int'
)
);
public function MyObjects(){
return $this->getManyManyComponents('MyObjects')->filter(array('Active' > 1))->sort('CategorySortOrder');
}
}
</code>
the last method "MyObjects()" of class Category returns all MyObjects that are active and that are related to the current category and orders them by CategorySortOrder.
Now my Question, how do I bring in the Tags Relation into here? I want to return the same data as above, but also the Objects returned should be related to one current Tag. Do I need to make an innerjoin and whicht table I have to join, as the Many-Many relation to tags is hold within a mapping table (tag_myobject)?
Can someone help me here?