datetime NOT NULL,
>> >>> PRIMARY KEY (`id`),
>> >>> FULLTEXT KEY `title` (`title`)
>> >>> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
>>
>> >>> PageView belongsTo Page:
>>
>> >>> CREATE TABLE IF NOT EXIS
int(11) NOT NULL,
> >>> `user_id` int(11) default NULL,
> >>> `user_ip` int(10) unsigned default NULL,
> >>> `created` datetime NOT NULL,
> >>> PRIMARY KEY (`id`)
> >>> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED;
>
> >>&
gt;>> Page hasMany PageView:
>>>>>
>>>>> CREATE TABLE IF NOT EXISTS `pages` (
>>>>> `id` int(11) NOT NULL auto_increment,
>>>>> `user_id` int(11) NOT NULL,
>>>>> `title` varchar(100) NOT NULL,
>>>>> `
gt; PageView belongsTo Page:
>>>>
>>>> CREATE TABLE IF NOT EXISTS `page_views` (
>>>> `id` int(11) NOT NULL auto_increment,
>>>> `page_id` int(11) NOT NULL,
>>>> `user_id` int(11) default NULL,
>>>> `user_ip` int(10) unsigned de
>>> PRIMARY KEY (`id`)
>>> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED;
>>>
>>> SQL query:
>>>
>>> SELECT Page.*, COUNT(*) AS views FROM
>>> pages AS Page
>>> INNER JOIN page_views AS PageView ON Page.id = Pa
;> ORDER BY COUNT(*) DESC
>> LIMIT 10 OFFSET 0;
>>
>> Returns these fields:
>>
>> id, user_id, title, slug, created, views
>>
>> The first five fields are those from the Page model and the sixth field,
>> views, is a count of how many times the
age model and the sixth field,
> views, is a count of how many times the Page.id primary key is used as a
> PageView.page_id foreign key.
>
> Thanks for the help. I know Cake is supposed to make SQL easier, but I am
> having trouble making the jump from SQL to Cake queries where the SQ
t'),
> 'order' => array('Post.view_count DESC'),
> 'limit' => 10
> )
> );
>
> this worked for me.
> >
>
>
--
View this message in context:
http://n2.nabble.com/Converting-SQL-query-to-Cake-query-tp2434189p2436388.html
Sent
$topTen = $this->Post->find('list',
array(
'fields' => array('Post.id', 'Post.view_count'),
'order' => array('Post.view_count DESC'),
'limit' => 10
)
);
this worked for me.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Gro
ssociations instead. Once
> you have an association, all related data will be returned, simply
> contain it or up the recursion.
> >
>
>
--
View this message in context:
http://n2.nabble.com/Converting-SQL-query-to-Cake-query-tp2434189p2435579.html
Sent from the CakeP
Remove that condition, you should be using associations instead. Once
you have an association, all related data will be returned, simply
contain it or up the recursion.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
#x27; => array('Page.id')
)
);
Can someone help me refine? Thank you.
--
View this message in context:
http://n2.nabble.com/Converting-SQL-query-to-Cake-query-tp2434189p2434189.html
Sent from the CakePHP mailing list archive at Nabble.com.
--~--~-~--~~---
12 matches
Mail list logo