Skip to content

Instantly share code, notes, and snippets.

@violetyk
Created January 25, 2012 08:38
Show Gist options
  • Save violetyk/1675466 to your computer and use it in GitHub Desktop.
Save violetyk/1675466 to your computer and use it in GitHub Desktop.
[cakephp]HABTMのfind。ランダムに。
<?php
// 所属カテゴリ内で、同じタグを持つコンテンツを取得。
$this->Content->Behaviors->attach('Matchable');
$options = array(
'jointo' => array(
'Tag' => array('type' => 'INNER'),
),
'conditions' => array(
'Tag.id' => Set::extract('/Tag/id', $content),
'Content.category_id' => Set::extract('/Category/id', $categories),
),
'limit' => $limit,
'recursive' => -1,
'order' => 'rand()',
'group' => 'Content.id'
);
return $this->Content->find('all', $options);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment