Skip to content

Instantly share code, notes, and snippets.

@trev
Last active December 18, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trev/5828556 to your computer and use it in GitHub Desktop.
Save trev/5828556 to your computer and use it in GitHub Desktop.
SS Many_many Join
<?php
public function filterStuff() {
// Can't use Search Filter since the object has a base class of SiteTree
// $results = PostPage::get()->filter(array('Authors.URLSegment:ExactMatch' = 'Trev'));
// Lets go manually
$results = PostPage::get()->leftJoin(
'PostPage_Authors',
'"PostPage_Authors"."PostPageID" = "PostPage"."ID"'
)->leftJoin(
'AuthorPage',
'"PostPage_Authors"."AuthorPageID" = "AuthorPage"."ID"'
)->leftJoin(
'SiteTree_Live',
'"SL2"."ID" = "PostPage_Authors"."AuthorPageID"',
'SL2'
)->where('"SL2"."URLSegment" = \'Trev\'');
return $results->renderWith('SomeTemplate');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment