A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearHow do I exclude records from an associated model in CakePHP? - page 1
User InfoPosts
How do I exclude records from an associated model in CakePHP?#1
I'm creating a Q&A application in CakePHP, and I want to exclude my associations in some cases. Imagine the following:

I'm listing all questions on the first page using $this->Question->findAll();. Since I have the following association in my model:

public $hasMany = array('Answer' =>
array('className' => 'Answer',
'order' => 'Answer.created DESC',
'foreignKey' => 'post_id',
'dependent' => true,
'exclusive' => false,
)
);


All answers will get selected at the start page, which is not optimal. How could i do to exclude the answers in this particular method?

Thanks

posted date: 2008-12-18 05:58:00


Re: How do I exclude records from an associated model in CakePHP?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-18 05:58:01


Re: How do I exclude records from an associated model in CakePHP?#3
I quick look at the CakePHP API reveals that you've got an unbindModel method on the Model.So in you example you can do this:$this->Question->unBindModel(array('hasMany' => array(’Answer’)))Alternatively, you can use the Containable behaviour to only select the pieces from MySQL that you require for the current page view.

posted date: 2008-12-18 06:20:00


Re: How do I exclude records from an associated model in CakePHP?#4
If you are using CakePHP 1.2 you should think about Containable Behaviour. See http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/ for details

posted date: 2008-12-18 06:39:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.