Re: How to "INNER Join" in Model ?
Didn't work for me. On Dec 7, 2007 8:47 AM, foxmask <[EMAIL PROTECTED]> wrote: > > Nice ! > > > On Dec 6, 10:48 pm, nate <[EMAIL PROTECTED]> wrote: > > > class ForumPerm extends AppModel { > > var $name = 'ForumPerm'; > > var $primaryKey = 'group_id,forum_id'; > > //The Associations below have been created with all possible > > keys, > > those that are not needed can be removed > > var $belongsTo = array( > > 'Group' => array('type' => 'INNER'), > > 'Forum' => array('type' => 'INNER') > > ); > > > > } > > > > On Dec 6, 12:28 pm, Baz <[EMAIL PROTECTED]> wrote: > > > > > I'm sorry, I'm a bit lost. > > > > > Could you explain this a lil more? > > > > > On Dec 6, 2007 10:15 AM, nate <[EMAIL PROTECTED]> wrote: > > > > > > On 1.2 you can set the 'type' key in the association, which defaults > > > > to "LEFT". > > > > > > On Dec 6, 7:39 am, foxmask <[EMAIL PROTECTED]> wrote: > > > > > Hi Baz > > > > > We suggested me to do this : > > > > > > > in the topics controller : > > > > > function lastTopics(){ > > > > > $sql = > > > > > "SELECT Topic.id, Topic.subject FROM topics AS Topic INNER JOIN > forums > > > > > AS Forum ON > > > > > Forum.id = Topic.forum_id LEFT JOIN forum_perms AS ForumPerm ON > > > > > (ForumPerm.forum_id=Forum.id AND > > > > > ForumPerm.group_id='xxx') WHERE (ForumPerm.read_forum IS NULL OR > > > > > ForumPerm.read_forum=1) > > > > > AND Topic.moved_to IS NULL ORDER BY Topic.last_post DESC LIMIT 10 > "; > > > > > $resultset = $this->Topic->query($sql); > > > > > return $resultset; > > > > > > > } > > > > > > > and in my element : > > > > > $pt_active_topics = $this->requestAction('topics/lastTopics/'); > > > > > > > On Dec 5, 9:59 pm, Baz L <[EMAIL PROTECTED]> wrote: > > > > > > > > I ran into a need for this today. > > > > > > > > In the interest of time, I just trim the array I get back after > the > > > > > > fact, however...is there someway to do this? > > > > > > -- > > > > > > Baz L > > > > > > Web Development 2.0http://WebDevelopment2.com/ > > > > > > > > On Dec 1, 1:30 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > > > > > > gooed evening > > > > > > > any idea aboutinner join? > > > > > > > > > On Nov 29, 12:39 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > > > > > > > Hi i'd like to know what i need to do and in what model, to > be > > > > able to > > > > > > > > use this SQL query > > > > > > > > > > SELECT t.id, t.subject FROM topics AS tINNER JOINforums AS f > ON > > > > > > > > f.id=t.forum_id LEFT JOIN forum_perms AS fp ON ( > fp.forum_id=f.idAND > > > > > > > > fp.group_id='xxx') WHERE (fp.read_forum IS NULL OR > fp.read_forum=1 > > > > ) > > > > > > > > AND t.moved_to IS NULL ORDER BY t.last_post DESC LIMIT 10 > > > > > > > > > > actually this SQL Query : > > > > > > > > SELECT `Post`.`id`, `Post`.`poster`, `Post`.`poster_id`, > > > > > > > > `Post`.`poster_ip`, `Post`.`poster_email`, `Post`.`message`, > > > > > > > > `Post`.`hide_smilies`, `Post`.`posted`, `Post`.`edited`, > > > > > > > > `Post`.`edited_by`, `Post`.`topic_id`, `Topic`.`id`, > > > > `Topic`.`poster`, > > > > > > > > `Topic`.`subject`, `Topic`.`posted`, `Topic`.`last_post`, > > > > > > > > `Topic`.`last_post_id`, `Topic`.`last_poster`, > > > > `Topic`.`num_views`, > > > > > > > > `Topic`.`num_replies`, `Topic`.`closed`, `Topic`.`sticky`, > > > > > > > > `Topic`.`moved_to`, `Topic`.`forum_id` FROM `posts` AS > `Post` LEFT > > > > > > > > JOIN `topics` AS `Topic` ON (`Post`.`topic_id` = > `Topic`.`id`) > > > > WHERE 1 > > > > > > > > = 1 ORDER BY `last_post` desc LIMIT 10 > > > > > > > > > > is produce when i do in my element : > > > > > > > > > > $pt_active_topics = > > > > $this->requestAction('posts/index/sort:last_post/ > > > > > > > > direction:desc/limit:10'); > > > > > > > > > > here are my models : > > > > > > > > > > > > > > > > > class Post extends AppModel { > > > > > > > > > > var $name = 'Post'; > > > > > > > > > > //The Associations below have been created with all > > > > possible keys, > > > > > > > > those that are not needed can be removed > > > > > > > > var $belongsTo = array( > > > > > > > > 'Topic' => array('className' => > 'Topic', > > > > > > 'foreignKey' => 'topic_id', > > > > > > 'conditions' => '', > > > > > > 'fields' => '', > > > > > > 'order' => '', > > > > > > 'counterCache' => ''), > > > > > > > > ); > > > > > > > > > > } > > > > > > > > > > > > > > > > > class Topic extends AppModel { > > > > > > > > > > var $name = 'Topic'; > > > > > > > > > > //The Associations below have been created with all > > > > possible keys, > > > > > > > > those that are not needed can be removed > > > > > > > > var $belongsTo = array( > > > > > > > > 'Forum' => array('className' => > 'Forum', > > > > > > 'foreignKey' => 'forum_id', > > > > > > 'conditions' => '', > > > > > > 'fields' => '', > > > > > > 'or
Re: How to "INNER Join" in Model ?
Nice ! On Dec 6, 10:48 pm, nate <[EMAIL PROTECTED]> wrote: > class ForumPerm extends AppModel { > var $name = 'ForumPerm'; > var $primaryKey = 'group_id,forum_id'; > //The Associations below have been created with all possible > keys, > those that are not needed can be removed > var $belongsTo = array( > 'Group' => array('type' => 'INNER'), > 'Forum' => array('type' => 'INNER') > ); > > } > > On Dec 6, 12:28 pm, Baz <[EMAIL PROTECTED]> wrote: > > > I'm sorry, I'm a bit lost. > > > Could you explain this a lil more? > > > On Dec 6, 2007 10:15 AM, nate <[EMAIL PROTECTED]> wrote: > > > > On 1.2 you can set the 'type' key in the association, which defaults > > > to "LEFT". > > > > On Dec 6, 7:39 am, foxmask <[EMAIL PROTECTED]> wrote: > > > > Hi Baz > > > > We suggested me to do this : > > > > > in the topics controller : > > > > function lastTopics(){ > > > > $sql = > > > > "SELECT Topic.id, Topic.subject FROM topics AS Topic INNER JOIN forums > > > > AS Forum ON > > > > Forum.id = Topic.forum_id LEFT JOIN forum_perms AS ForumPerm ON > > > > (ForumPerm.forum_id=Forum.id AND > > > > ForumPerm.group_id='xxx') WHERE (ForumPerm.read_forum IS NULL OR > > > > ForumPerm.read_forum=1) > > > > AND Topic.moved_to IS NULL ORDER BY Topic.last_post DESC LIMIT 10 "; > > > > $resultset = $this->Topic->query($sql); > > > > return $resultset; > > > > > } > > > > > and in my element : > > > > $pt_active_topics = $this->requestAction('topics/lastTopics/'); > > > > > On Dec 5, 9:59 pm, Baz L <[EMAIL PROTECTED]> wrote: > > > > > > I ran into a need for this today. > > > > > > In the interest of time, I just trim the array I get back after the > > > > > fact, however...is there someway to do this? > > > > > -- > > > > > Baz L > > > > > Web Development 2.0http://WebDevelopment2.com/ > > > > > > On Dec 1, 1:30 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > > > > gooed evening > > > > > > any idea aboutinner join? > > > > > > > On Nov 29, 12:39 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > > > > > Hi i'd like to know what i need to do and in what model, to be > > > able to > > > > > > > use this SQL query > > > > > > > > SELECT t.id, t.subject FROM topics AS tINNER JOINforums AS f ON > > > > > > > f.id=t.forum_id LEFT JOIN forum_perms AS fp ON > > > > > > > (fp.forum_id=f.idAND > > > > > > > fp.group_id='xxx') WHERE (fp.read_forum IS NULL OR fp.read_forum=1 > > > ) > > > > > > > AND t.moved_to IS NULL ORDER BY t.last_post DESC LIMIT 10 > > > > > > > > actually this SQL Query : > > > > > > > SELECT `Post`.`id`, `Post`.`poster`, `Post`.`poster_id`, > > > > > > > `Post`.`poster_ip`, `Post`.`poster_email`, `Post`.`message`, > > > > > > > `Post`.`hide_smilies`, `Post`.`posted`, `Post`.`edited`, > > > > > > > `Post`.`edited_by`, `Post`.`topic_id`, `Topic`.`id`, > > > `Topic`.`poster`, > > > > > > > `Topic`.`subject`, `Topic`.`posted`, `Topic`.`last_post`, > > > > > > > `Topic`.`last_post_id`, `Topic`.`last_poster`, > > > `Topic`.`num_views`, > > > > > > > `Topic`.`num_replies`, `Topic`.`closed`, `Topic`.`sticky`, > > > > > > > `Topic`.`moved_to`, `Topic`.`forum_id` FROM `posts` AS `Post` LEFT > > > > > > > JOIN `topics` AS `Topic` ON (`Post`.`topic_id` = `Topic`.`id`) > > > WHERE 1 > > > > > > > = 1 ORDER BY `last_post` desc LIMIT 10 > > > > > > > > is produce when i do in my element : > > > > > > > > $pt_active_topics = > > > $this->requestAction('posts/index/sort:last_post/ > > > > > > > direction:desc/limit:10'); > > > > > > > > here are my models : > > > > > > > > > > > > > > class Post extends AppModel { > > > > > > > > var $name = 'Post'; > > > > > > > > //The Associations below have been created with all > > > possible keys, > > > > > > > those that are not needed can be removed > > > > > > > var $belongsTo = array( > > > > > > > 'Topic' => array('className' => 'Topic', > > > > 'foreignKey' => 'topic_id', > > > > 'conditions' => '', > > > > 'fields' => '', > > > > 'order' => '', > > > > 'counterCache' => ''), > > > > > > > ); > > > > > > > > } > > > > > > > > > > > > > > class Topic extends AppModel { > > > > > > > > var $name = 'Topic'; > > > > > > > > //The Associations below have been created with all > > > possible keys, > > > > > > > those that are not needed can be removed > > > > > > > var $belongsTo = array( > > > > > > > 'Forum' => array('className' => 'Forum', > > > > 'foreignKey' => 'forum_id', > > > > 'conditions' => '', > > > > 'fields' => '', > > > > 'order' => '', > > > > 'counterCache' => ''), > > > > > > > ); > > > > > > > > var $hasMany = array( > > > > > > > 'Post' => array('className' => 'Post', > > > > 'foreignKey' => 'topic_id', > > > > 'conditions' => '', > > > > 'fields' => '', > > > > 'order' => '', > > > > 'dependent' => ''), > > > > > > > ); > > > > > > > > } >
Re: How to "INNER Join" in Model ?
array('type' => 'INNER'), 'Forum' => array('type' => 'INNER') ); } On Dec 6, 12:28 pm, Baz <[EMAIL PROTECTED]> wrote: > I'm sorry, I'm a bit lost. > > Could you explain this a lil more? > > On Dec 6, 2007 10:15 AM, nate <[EMAIL PROTECTED]> wrote: > > > > > On 1.2 you can set the 'type' key in the association, which defaults > > to "LEFT". > > > On Dec 6, 7:39 am, foxmask <[EMAIL PROTECTED]> wrote: > > > Hi Baz > > > We suggested me to do this : > > > > in the topics controller : > > > function lastTopics(){ > > > $sql = > > > "SELECT Topic.id, Topic.subject FROM topics AS Topic INNER JOIN forums > > > AS Forum ON > > > Forum.id = Topic.forum_id LEFT JOIN forum_perms AS ForumPerm ON > > > (ForumPerm.forum_id=Forum.id AND > > > ForumPerm.group_id='xxx') WHERE (ForumPerm.read_forum IS NULL OR > > > ForumPerm.read_forum=1) > > > AND Topic.moved_to IS NULL ORDER BY Topic.last_post DESC LIMIT 10 "; > > > $resultset = $this->Topic->query($sql); > > > return $resultset; > > > > } > > > > and in my element : > > > $pt_active_topics = $this->requestAction('topics/lastTopics/'); > > > > On Dec 5, 9:59 pm, Baz L <[EMAIL PROTECTED]> wrote: > > > > > I ran into a need for this today. > > > > > In the interest of time, I just trim the array I get back after the > > > > fact, however...is there someway to do this? > > > > -- > > > > Baz L > > > > Web Development 2.0http://WebDevelopment2.com/ > > > > > On Dec 1, 1:30 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > > > gooed evening > > > > > any idea aboutinner join? > > > > > > On Nov 29, 12:39 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > > > > Hi i'd like to know what i need to do and in what model, to be > > able to > > > > > > use this SQL query > > > > > > > SELECT t.id, t.subject FROM topics AS tINNER JOINforums AS f ON > > > > > > f.id=t.forum_id LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.idAND > > > > > > fp.group_id='xxx') WHERE (fp.read_forum IS NULL OR fp.read_forum=1 > > ) > > > > > > AND t.moved_to IS NULL ORDER BY t.last_post DESC LIMIT 10 > > > > > > > actually this SQL Query : > > > > > > SELECT `Post`.`id`, `Post`.`poster`, `Post`.`poster_id`, > > > > > > `Post`.`poster_ip`, `Post`.`poster_email`, `Post`.`message`, > > > > > > `Post`.`hide_smilies`, `Post`.`posted`, `Post`.`edited`, > > > > > > `Post`.`edited_by`, `Post`.`topic_id`, `Topic`.`id`, > > `Topic`.`poster`, > > > > > > `Topic`.`subject`, `Topic`.`posted`, `Topic`.`last_post`, > > > > > > `Topic`.`last_post_id`, `Topic`.`last_poster`, > > `Topic`.`num_views`, > > > > > > `Topic`.`num_replies`, `Topic`.`closed`, `Topic`.`sticky`, > > > > > > `Topic`.`moved_to`, `Topic`.`forum_id` FROM `posts` AS `Post` LEFT > > > > > > JOIN `topics` AS `Topic` ON (`Post`.`topic_id` = `Topic`.`id`) > > WHERE 1 > > > > > > = 1 ORDER BY `last_post` desc LIMIT 10 > > > > > > > is produce when i do in my element : > > > > > > > $pt_active_topics = > > $this->requestAction('posts/index/sort:last_post/ > > > > > > direction:desc/limit:10'); > > > > > > > here are my models : > > > > > > > > > > > > class Post extends AppModel { > > > > > > > var $name = 'Post'; > > > > > > > //The Associations below have been created with all > > possible keys, > > > > > > those that are not needed can be removed > > > > > > var $belongsTo = array( > > > > > > 'Topic' => array('className' => 'Topic', > > > 'foreignKey' => 'topic_id', > > > 'conditions' => '', > > > 'fields' => '', > > > 'order' => '', > > > 'counterCache' => ''), > > > > > > ); > > > > > > > } > > > > > > > > > > > > class Topic extends AppModel { > > > > > > > var $name = 'Topic'; > > > > > > > //The Associations below have been created with all > > possible keys, > > > > > > those that are not needed can be removed > > > > > > var $belongsTo = array( > > > > > > 'Forum' => array('className' => 'Forum', > > > 'foreignKey' => 'forum_id', > > > 'conditions' => '', > > > 'fields' => '', > > > 'order' => '', > > > 'counterCache' => ''), > > > > > > ); > > > > > > > var $hasMany = array( > > > > > > 'Post' => array('className' => 'Post', > > > 'foreignKey' => 'topic_id', > > > 'conditions' => '', > > > 'fields' => '', > > > 'order' => '', > > > 'dependent' => ''), > > > > > > ); > > > > > > > } > > > > > > > > > > > > class Forum extends AppModel { > > > > > > > var $name = 'Forum'; > > > > > > > //The Associations below have been created with all > > possible keys, > > > > > > those that are not needed can be removed > > > > > > var $hasMany = array( > > > > > > 'ForumPerm' => array('className' => > > 'ForumPerm', > > > 'foreignKey' => 'forum_id', > > > 'conditions' => '', > > > 'fields' => '', > > > 'order' => '', > > > 'limit' => '', > > > 'offset' => '', > > > 'dependent' => '', > > > 'exclusive' => '', > > > 'finderQuery' => ''
Re: How to "INNER Join" in Model ?
I'm sorry, I'm a bit lost. Could you explain this a lil more? On Dec 6, 2007 10:15 AM, nate <[EMAIL PROTECTED]> wrote: > > On 1.2 you can set the 'type' key in the association, which defaults > to "LEFT". > > On Dec 6, 7:39 am, foxmask <[EMAIL PROTECTED]> wrote: > > Hi Baz > > We suggested me to do this : > > > > in the topics controller : > > function lastTopics(){ > > $sql = > > "SELECT Topic.id, Topic.subject FROM topics AS Topic INNER JOIN forums > > AS Forum ON > > Forum.id = Topic.forum_id LEFT JOIN forum_perms AS ForumPerm ON > > (ForumPerm.forum_id=Forum.id AND > > ForumPerm.group_id='xxx') WHERE (ForumPerm.read_forum IS NULL OR > > ForumPerm.read_forum=1) > > AND Topic.moved_to IS NULL ORDER BY Topic.last_post DESC LIMIT 10 "; > > $resultset = $this->Topic->query($sql); > > return $resultset; > > > > } > > > > and in my element : > > $pt_active_topics = $this->requestAction('topics/lastTopics/'); > > > > On Dec 5, 9:59 pm, Baz L <[EMAIL PROTECTED]> wrote: > > > > > I ran into a need for this today. > > > > > In the interest of time, I just trim the array I get back after the > > > fact, however...is there someway to do this? > > > -- > > > Baz L > > > Web Development 2.0http://WebDevelopment2.com/ > > > > > On Dec 1, 1:30 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > > > gooed evening > > > > any idea aboutinner join? > > > > > > On Nov 29, 12:39 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > > > > Hi i'd like to know what i need to do and in what model, to be > able to > > > > > use this SQL query > > > > > > > SELECT t.id, t.subject FROM topics AS tINNER JOINforums AS f ON > > > > > f.id=t.forum_id LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.idAND > > > > > fp.group_id='xxx') WHERE (fp.read_forum IS NULL OR fp.read_forum=1 > ) > > > > > AND t.moved_to IS NULL ORDER BY t.last_post DESC LIMIT 10 > > > > > > > actually this SQL Query : > > > > > SELECT `Post`.`id`, `Post`.`poster`, `Post`.`poster_id`, > > > > > `Post`.`poster_ip`, `Post`.`poster_email`, `Post`.`message`, > > > > > `Post`.`hide_smilies`, `Post`.`posted`, `Post`.`edited`, > > > > > `Post`.`edited_by`, `Post`.`topic_id`, `Topic`.`id`, > `Topic`.`poster`, > > > > > `Topic`.`subject`, `Topic`.`posted`, `Topic`.`last_post`, > > > > > `Topic`.`last_post_id`, `Topic`.`last_poster`, > `Topic`.`num_views`, > > > > > `Topic`.`num_replies`, `Topic`.`closed`, `Topic`.`sticky`, > > > > > `Topic`.`moved_to`, `Topic`.`forum_id` FROM `posts` AS `Post` LEFT > > > > > JOIN `topics` AS `Topic` ON (`Post`.`topic_id` = `Topic`.`id`) > WHERE 1 > > > > > = 1 ORDER BY `last_post` desc LIMIT 10 > > > > > > > is produce when i do in my element : > > > > > > > $pt_active_topics = > $this->requestAction('posts/index/sort:last_post/ > > > > > direction:desc/limit:10'); > > > > > > > here are my models : > > > > > > > > > > > class Post extends AppModel { > > > > > > > var $name = 'Post'; > > > > > > > //The Associations below have been created with all > possible keys, > > > > > those that are not needed can be removed > > > > > var $belongsTo = array( > > > > > 'Topic' => array('className' => 'Topic', > > > > > > 'foreignKey' => 'topic_id', > > > > > > 'conditions' => '', > > > > > > 'fields' => '', > > > > > > 'order' => '', > > > > > > 'counterCache' => ''), > > > > > ); > > > > > > > } > > > > > > > > > > > class Topic extends AppModel { > > > > > > > var $name = 'Topic'; > > > > > > > //The Associations below have been created with all > possible keys, > > > > > those that are not needed can be removed > > > > > var $belongsTo = array( > > > > > 'Forum' => array('className' => 'Forum', > > > > > > 'foreignKey' => 'forum_id', > > > > > > 'conditions' => '', > > > > > > 'fields' => '', > > > > > > 'order' => '', > > > > > > 'counterCache' => ''), > > > > > ); > > > > > > > var $hasMany = array( > > > > > 'Post' => array('className' => 'Post', > > > > > > 'foreignKey' => 'topic_id', > > > > > > 'conditions' => '', > > > > > > 'fields' => '', > > > > > > 'order' => '', > > > > > > 'dependent' => ''), > > > > > ); > > > > > > > } > > > > > > > > > > > class Forum extends AppModel { > > > > > > > var $name = 'Forum'; > > > > > > > //The Associations below have been created with all > possible keys, > > > > > those that are not needed can be removed > > > > > var $hasMany = array( > > > > > 'ForumPerm' => array('className' => > 'ForumPerm', > > > > > > 'foreignKey' => 'forum_id', > > > > > > 'conditions' => '', > > > > > > 'fields' => '', > > > > > > 'order' => '', > > > > > > 'limit' => '', > > > > > > 'offset' => '', > > > > > > 'dependent' => '', > > > > > > 'exclusive' => '', > > > > > > 'finderQuery' => '', > > > > > > 'counterQuery' => ''), > > > > > 'Topic' => array('className' => 'Topic', > > > > > > 'foreignKey' => 'forum_
Re: How to "INNER Join" in Model ?
On 1.2 you can set the 'type' key in the association, which defaults to "LEFT". On Dec 6, 7:39 am, foxmask <[EMAIL PROTECTED]> wrote: > Hi Baz > We suggested me to do this : > > in the topics controller : > function lastTopics(){ > $sql = > "SELECT Topic.id, Topic.subject FROM topics AS Topic INNER JOIN forums > AS Forum ON > Forum.id = Topic.forum_id LEFT JOIN forum_perms AS ForumPerm ON > (ForumPerm.forum_id=Forum.id AND > ForumPerm.group_id='xxx') WHERE (ForumPerm.read_forum IS NULL OR > ForumPerm.read_forum=1) > AND Topic.moved_to IS NULL ORDER BY Topic.last_post DESC LIMIT 10 "; > $resultset = $this->Topic->query($sql); > return $resultset; > > } > > and in my element : > $pt_active_topics = $this->requestAction('topics/lastTopics/'); > > On Dec 5, 9:59 pm, Baz L <[EMAIL PROTECTED]> wrote: > > > I ran into a need for this today. > > > In the interest of time, I just trim the array I get back after the > > fact, however...is there someway to do this? > > -- > > Baz L > > Web Development 2.0http://WebDevelopment2.com/ > > > On Dec 1, 1:30 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > gooed evening > > > any idea aboutinner join? > > > > On Nov 29, 12:39 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > > Hi i'd like to know what i need to do and in what model, to be able to > > > > use this SQL query > > > > > SELECT t.id, t.subject FROM topics AS tINNER JOINforums AS f ON > > > > f.id=t.forum_id LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.id AND > > > > fp.group_id='xxx') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) > > > > AND t.moved_to IS NULL ORDER BY t.last_post DESC LIMIT 10 > > > > > actually this SQL Query : > > > > SELECT `Post`.`id`, `Post`.`poster`, `Post`.`poster_id`, > > > > `Post`.`poster_ip`, `Post`.`poster_email`, `Post`.`message`, > > > > `Post`.`hide_smilies`, `Post`.`posted`, `Post`.`edited`, > > > > `Post`.`edited_by`, `Post`.`topic_id`, `Topic`.`id`, `Topic`.`poster`, > > > > `Topic`.`subject`, `Topic`.`posted`, `Topic`.`last_post`, > > > > `Topic`.`last_post_id`, `Topic`.`last_poster`, `Topic`.`num_views`, > > > > `Topic`.`num_replies`, `Topic`.`closed`, `Topic`.`sticky`, > > > > `Topic`.`moved_to`, `Topic`.`forum_id` FROM `posts` AS `Post` LEFT > > > > JOIN `topics` AS `Topic` ON (`Post`.`topic_id` = `Topic`.`id`) WHERE 1 > > > > = 1 ORDER BY `last_post` desc LIMIT 10 > > > > > is produce when i do in my element : > > > > > $pt_active_topics = $this->requestAction('posts/index/sort:last_post/ > > > > direction:desc/limit:10'); > > > > > here are my models : > > > > > > > > class Post extends AppModel { > > > > > var $name = 'Post'; > > > > > //The Associations below have been created with all possible > > > > keys, > > > > those that are not needed can be removed > > > > var $belongsTo = array( > > > > 'Topic' => array('className' => 'Topic', > > > > > > > > 'foreignKey' => 'topic_id', > > > > > > > > 'conditions' => '', > > > > > > > > 'fields' => '', > > > > 'order' > > > > => '', > > > > > > > > 'counterCache' => ''), > > > > ); > > > > > } > > > > > > > > class Topic extends AppModel { > > > > > var $name = 'Topic'; > > > > > //The Associations below have been created with all possible > > > > keys, > > > > those that are not needed can be removed > > > > var $belongsTo = array( > > > > 'Forum' => array('className' => 'Forum', > > > > > > > > 'foreignKey' => 'forum_id', > > > > > > > > 'conditions' => '', > > > > > > > > 'fields' => '', > > > > 'order' > > > > => '', > > > > > > > > 'counterCache' => ''), > > > > ); > > > > > var $hasMany = array( > > > > 'Post' => array('className' => 'Post', > > > > > > > > 'foreignKey' => 'topic_id', > > > > > > > > 'conditions' => '', > > > > > > > > 'fields' => '', > > > > 'order' > > > > => '', > > > > > > > > 'dependent' => ''), > > > > ); > > > > > } > > > > > > > > class Forum extends AppModel { > > > > > v
Re: How to "INNER Join" in Model ?
Hi Baz We suggested me to do this : in the topics controller : function lastTopics(){ $sql = "SELECT Topic.id, Topic.subject FROM topics AS Topic INNER JOIN forums AS Forum ON Forum.id = Topic.forum_id LEFT JOIN forum_perms AS ForumPerm ON (ForumPerm.forum_id=Forum.id AND ForumPerm.group_id='xxx') WHERE (ForumPerm.read_forum IS NULL OR ForumPerm.read_forum=1) AND Topic.moved_to IS NULL ORDER BY Topic.last_post DESC LIMIT 10 "; $resultset = $this->Topic->query($sql); return $resultset; } and in my element : $pt_active_topics = $this->requestAction('topics/lastTopics/'); On Dec 5, 9:59 pm, Baz L <[EMAIL PROTECTED]> wrote: > I ran into a need for this today. > > In the interest of time, I just trim the array I get back after the > fact, however...is there someway to do this? > -- > Baz L > Web Development 2.0http://WebDevelopment2.com/ > > On Dec 1, 1:30 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > gooed evening > > any idea aboutinner join? > > > On Nov 29, 12:39 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > > Hi i'd like to know what i need to do and in what model, to be able to > > > use this SQL query > > > > SELECT t.id, t.subject FROM topics AS tINNER JOINforums AS f ON > > > f.id=t.forum_id LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.id AND > > > fp.group_id='xxx') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) > > > AND t.moved_to IS NULL ORDER BY t.last_post DESC LIMIT 10 > > > > actually this SQL Query : > > > SELECT `Post`.`id`, `Post`.`poster`, `Post`.`poster_id`, > > > `Post`.`poster_ip`, `Post`.`poster_email`, `Post`.`message`, > > > `Post`.`hide_smilies`, `Post`.`posted`, `Post`.`edited`, > > > `Post`.`edited_by`, `Post`.`topic_id`, `Topic`.`id`, `Topic`.`poster`, > > > `Topic`.`subject`, `Topic`.`posted`, `Topic`.`last_post`, > > > `Topic`.`last_post_id`, `Topic`.`last_poster`, `Topic`.`num_views`, > > > `Topic`.`num_replies`, `Topic`.`closed`, `Topic`.`sticky`, > > > `Topic`.`moved_to`, `Topic`.`forum_id` FROM `posts` AS `Post` LEFT > > > JOIN `topics` AS `Topic` ON (`Post`.`topic_id` = `Topic`.`id`) WHERE 1 > > > = 1 ORDER BY `last_post` desc LIMIT 10 > > > > is produce when i do in my element : > > > > $pt_active_topics = $this->requestAction('posts/index/sort:last_post/ > > > direction:desc/limit:10'); > > > > here are my models : > > > > > > class Post extends AppModel { > > > > var $name = 'Post'; > > > > //The Associations below have been created with all possible keys, > > > those that are not needed can be removed > > > var $belongsTo = array( > > > 'Topic' => array('className' => 'Topic', > > > > > > 'foreignKey' => 'topic_id', > > > > > > 'conditions' => '', > > > 'fields' > > > => '', > > > 'order' > > > => '', > > > > > > 'counterCache' => ''), > > > ); > > > > } > > > > > > class Topic extends AppModel { > > > > var $name = 'Topic'; > > > > //The Associations below have been created with all possible keys, > > > those that are not needed can be removed > > > var $belongsTo = array( > > > 'Forum' => array('className' => 'Forum', > > > > > > 'foreignKey' => 'forum_id', > > > > > > 'conditions' => '', > > > 'fields' > > > => '', > > > 'order' > > > => '', > > > > > > 'counterCache' => ''), > > > ); > > > > var $hasMany = array( > > > 'Post' => array('className' => 'Post', > > > > > > 'foreignKey' => 'topic_id', > > > > > > 'conditions' => '', > > > 'fields' > > > => '', > > > 'order' > > > => '', > > > > > > 'dependent' => ''), > > > ); > > > > } > > > > > > class Forum extends AppModel { > > > > var $name = 'Forum'; > > > > //The Associations below have been created with all possible keys, > > > those that are not needed can be removed > > > var $hasMany = array( > > > 'ForumPerm' => array('className' => 'ForumPerm', > > > > > > 'foreignKey' => 'for
Re: How to "INNER Join" in Model ?
I ran into a need for this today. In the interest of time, I just trim the array I get back after the fact, however...is there someway to do this? -- Baz L Web Development 2.0 http://WebDevelopment2.com/ On Dec 1, 1:30 pm, foxmask <[EMAIL PROTECTED]> wrote: > gooed evening > any idea aboutinner join? > > On Nov 29, 12:39 pm, foxmask <[EMAIL PROTECTED]> wrote: > > > Hi i'd like to know what i need to do and in what model, to be able to > > use this SQL query > > > SELECT t.id, t.subject FROM topics AS tINNER JOINforums AS f ON > > f.id=t.forum_id LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.id AND > > fp.group_id='xxx') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) > > AND t.moved_to IS NULL ORDER BY t.last_post DESC LIMIT 10 > > > actually this SQL Query : > > SELECT `Post`.`id`, `Post`.`poster`, `Post`.`poster_id`, > > `Post`.`poster_ip`, `Post`.`poster_email`, `Post`.`message`, > > `Post`.`hide_smilies`, `Post`.`posted`, `Post`.`edited`, > > `Post`.`edited_by`, `Post`.`topic_id`, `Topic`.`id`, `Topic`.`poster`, > > `Topic`.`subject`, `Topic`.`posted`, `Topic`.`last_post`, > > `Topic`.`last_post_id`, `Topic`.`last_poster`, `Topic`.`num_views`, > > `Topic`.`num_replies`, `Topic`.`closed`, `Topic`.`sticky`, > > `Topic`.`moved_to`, `Topic`.`forum_id` FROM `posts` AS `Post` LEFT > > JOIN `topics` AS `Topic` ON (`Post`.`topic_id` = `Topic`.`id`) WHERE 1 > > = 1 ORDER BY `last_post` desc LIMIT 10 > > > is produce when i do in my element : > > > $pt_active_topics = $this->requestAction('posts/index/sort:last_post/ > > direction:desc/limit:10'); > > > here are my models : > > > > class Post extends AppModel { > > > var $name = 'Post'; > > > //The Associations below have been created with all possible keys, > > those that are not needed can be removed > > var $belongsTo = array( > > 'Topic' => array('className' => 'Topic', > > > > 'foreignKey' => 'topic_id', > > > > 'conditions' => '', > > 'fields' => > > '', > > 'order' => > > '', > > > > 'counterCache' => ''), > > ); > > > } > > > > class Topic extends AppModel { > > > var $name = 'Topic'; > > > //The Associations below have been created with all possible keys, > > those that are not needed can be removed > > var $belongsTo = array( > > 'Forum' => array('className' => 'Forum', > > > > 'foreignKey' => 'forum_id', > > > > 'conditions' => '', > > 'fields' => > > '', > > 'order' => > > '', > > > > 'counterCache' => ''), > > ); > > > var $hasMany = array( > > 'Post' => array('className' => 'Post', > > > > 'foreignKey' => 'topic_id', > > > > 'conditions' => '', > > 'fields' => > > '', > > 'order' => > > '', > > 'dependent' > > => ''), > > ); > > > } > > > > class Forum extends AppModel { > > > var $name = 'Forum'; > > > //The Associations below have been created with all possible keys, > > those that are not needed can be removed > > var $hasMany = array( > > 'ForumPerm' => array('className' => 'ForumPerm', > > > > 'foreignKey' => 'forum_id', > > > > 'conditions' => '', > > 'fields' => > > '', > > 'order' => > > '', > > 'limit' => > > '', > > 'offset' => > > '', > > 'dependent' > > => '', > > 'exclusive' > > => '', > > > > 'finderQuery' => '', > > > > 'counterQuery' =
Re: How to "INNER Join" in Model ?
gooed evening any idea about inner join ? On Nov 29, 12:39 pm, foxmask <[EMAIL PROTECTED]> wrote: > Hi i'd like to know what i need to do and in what model, to be able to > use this SQL query > > SELECT t.id, t.subject FROM topics AS t INNER JOIN forums AS f ON > f.id=t.forum_id LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.id AND > fp.group_id='xxx') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) > AND t.moved_to IS NULL ORDER BY t.last_post DESC LIMIT 10 > > actually this SQL Query : > SELECT `Post`.`id`, `Post`.`poster`, `Post`.`poster_id`, > `Post`.`poster_ip`, `Post`.`poster_email`, `Post`.`message`, > `Post`.`hide_smilies`, `Post`.`posted`, `Post`.`edited`, > `Post`.`edited_by`, `Post`.`topic_id`, `Topic`.`id`, `Topic`.`poster`, > `Topic`.`subject`, `Topic`.`posted`, `Topic`.`last_post`, > `Topic`.`last_post_id`, `Topic`.`last_poster`, `Topic`.`num_views`, > `Topic`.`num_replies`, `Topic`.`closed`, `Topic`.`sticky`, > `Topic`.`moved_to`, `Topic`.`forum_id` FROM `posts` AS `Post` LEFT > JOIN `topics` AS `Topic` ON (`Post`.`topic_id` = `Topic`.`id`) WHERE 1 > = 1 ORDER BY `last_post` desc LIMIT 10 > > is produce when i do in my element : > > $pt_active_topics = $this->requestAction('posts/index/sort:last_post/ > direction:desc/limit:10'); > > here are my models : > > class Post extends AppModel { > > var $name = 'Post'; > > //The Associations below have been created with all possible keys, > those that are not needed can be removed > var $belongsTo = array( > 'Topic' => array('className' => 'Topic', > 'foreignKey' > => 'topic_id', > 'conditions' > => '', > 'fields' => > '', > 'order' => '', > > 'counterCache' => ''), > ); > > } > > class Topic extends AppModel { > > var $name = 'Topic'; > > //The Associations below have been created with all possible keys, > those that are not needed can be removed > var $belongsTo = array( > 'Forum' => array('className' => 'Forum', > 'foreignKey' > => 'forum_id', > 'conditions' > => '', > 'fields' => > '', > 'order' => '', > > 'counterCache' => ''), > ); > > var $hasMany = array( > 'Post' => array('className' => 'Post', > 'foreignKey' > => 'topic_id', > 'conditions' > => '', > 'fields' => > '', > 'order' => '', > 'dependent' > => ''), > ); > > } > > class Forum extends AppModel { > > var $name = 'Forum'; > > //The Associations below have been created with all possible keys, > those that are not needed can be removed > var $hasMany = array( > 'ForumPerm' => array('className' => 'ForumPerm', > 'foreignKey' > => 'forum_id', > 'conditions' > => '', > 'fields' => > '', > 'order' => '', > 'limit' => '', > 'offset' => > '', > 'dependent' > => '', > 'exclusive' > => '', > 'finderQuery' > => '', > > 'counterQuery' => ''), > 'Topic' => array('className' => 'Topic', > 'foreignKey' > => 'forum_id', > 'conditions' > => '', > 'fields' => > '', > 'order' => '', >
How to "INNER Join" in Model ?
Hi i'd like to know what i need to do and in what model, to be able to use this SQL query SELECT t.id, t.subject FROM topics AS t INNER JOIN forums AS f ON f.id=t.forum_id LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='xxx') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL ORDER BY t.last_post DESC LIMIT 10 actually this SQL Query : SELECT `Post`.`id`, `Post`.`poster`, `Post`.`poster_id`, `Post`.`poster_ip`, `Post`.`poster_email`, `Post`.`message`, `Post`.`hide_smilies`, `Post`.`posted`, `Post`.`edited`, `Post`.`edited_by`, `Post`.`topic_id`, `Topic`.`id`, `Topic`.`poster`, `Topic`.`subject`, `Topic`.`posted`, `Topic`.`last_post`, `Topic`.`last_post_id`, `Topic`.`last_poster`, `Topic`.`num_views`, `Topic`.`num_replies`, `Topic`.`closed`, `Topic`.`sticky`, `Topic`.`moved_to`, `Topic`.`forum_id` FROM `posts` AS `Post` LEFT JOIN `topics` AS `Topic` ON (`Post`.`topic_id` = `Topic`.`id`) WHERE 1 = 1 ORDER BY `last_post` desc LIMIT 10 is produce when i do in my element : $pt_active_topics = $this->requestAction('posts/index/sort:last_post/ direction:desc/limit:10'); here are my models : array('className' => 'Topic', 'foreignKey' => 'topic_id', 'conditions' => '', 'fields' => '', 'order' => '', 'counterCache' => ''), ); } array('className' => 'Forum', 'foreignKey' => 'forum_id', 'conditions' => '', 'fields' => '', 'order' => '', 'counterCache' => ''), ); var $hasMany = array( 'Post' => array('className' => 'Post', 'foreignKey' => 'topic_id', 'conditions' => '', 'fields' => '', 'order' => '', 'dependent' => ''), ); } array('className' => 'ForumPerm', 'foreignKey' => 'forum_id', 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'dependent' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => ''), 'Topic' => array('className' => 'Topic', 'foreignKey' => 'forum_id', 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'dependent' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => ''), ); } ?> array('className' => 'Group', 'foreignKey' => 'group_id', 'conditions' => '', 'fields' => '', 'order' => '', 'counterCache' => ''), 'Forum' => array('className' => 'Forum', 'f