Skip to content

Instantly share code, notes, and snippets.

@econic
Created July 5, 2012 10:25
Show Gist options
  • Save econic/3052834 to your computer and use it in GitHub Desktop.
Save econic/3052834 to your computer and use it in GitHub Desktop.
Fake bidirectional MM table
class Tx_ext_Domain_Model_Category extends Tx_Extbase_DomainObject_AbstractEntity {
/**
* returns all the FAQs linked with this Category
*
* @return Tx_Extbase_Persistence_ObjectStorage<Tx_ext_Domain_Model_Faq>
*/
public function getFaqs() {
return t3lib_div::makeInstance('Tx_ext_Domain_Repository_FaqRepository')->byCategory($this);
}
}
class Tx_ext_Domain_Model_Faq extends Tx_Extbase_DomainObject_AbstractEntity {
/**
* Categories
*
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_ext_Domain_Model_Category>
*/
protected $categories;
/**
* Returns the categories
*
* @return Tx_Extbase_Persistence_ObjectStorage<Tx_ext_Domain_Model_Category> $categories
*/
public function getCategories() {
return $this->categories;
}
}
class Tx_ext_Domain_Repository_FaqRepository extends Tx_Extbase_Persistence_Repository {
public function byCategory(Tx_ext_Domain_Model_Category $category) {
$query = $this->createQuery();
$query->matching( $query->contains('categories', $category) );
return $query->execute();
}
}
your FAQ {faq} has the categories {faq.categories}
your Category {category} has the FAQs {category.faqs}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment