class User extends AppModel{
public $hasMany = array(
'Item',
'RecentItem' => array(
'class' => 'Item',
'conditions' => array(
...your conditions...
)
);
}
Jeremy Burns
Class Outfit
http://www.classoutfit.com
On 7 Dec 2011, at 07:5818, Todong wrote:
> Users can create Items, once the Item is created, the Item belongsTo
> User, and the User hasMany Item.
> class User extends AppModel{
> public $hasMany = 'Item';
> }
> class Item extends AppModel{
> public $belongsTo = 'User';
> }
> class ItemsController extends AppController{
> function add(){
> ...(post form data)
> $this->request->data['Item']['user_id'] = $this->Auth->user('id');
> ...(save Item)
> }
> }
>
> Now I wanna get User's recently visited Items, I know I can use
> HABTM(join table) to define the relationship for second time, But when
> I wanna get User's recently commented Items, How could I define the
> relationship in Cake? (Can I use hasMany or belongsTo still, or use
> another new join table?)
>
> Any suggestion is appreciated.
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php