Tuesday, December 6, 2011

User has both published Items and visited Items?

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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate