Please have a look at 'Sub-queries' section of http://book.cakephp.org/view/1030/Complex-Find-Conditions (at the end of the page), hope it helps.
Amit Badkas
PHP Applications for E-Biz: http://www.sanisoft.com
On Fri, Dec 31, 2010 at 8:15 PM, aughrt <julijonas.kikutis@gmail.com> wrote:
Hello!
I would like to know the best way to accomplish this task in this
framework.
CakePHP 1.3, MySQL
Company(id, name)
FormerExecutive(id, name, company_id)
Company hasMany FormerExecutive
FormerExecutive belongsTo Company
Now I am building a search action in CompanyController:
function search() {
// check if submitted search params
if ($this->data['Company']) {
// parse keywords param
if ($keywords = $this->data['Company']['keywords']) {
$conditions['OR'] = array(
'Company.name LIKE' =>
"%$keywords%",
// this line is errorneous:
'FormerExecutive.name LIKE' =>
"%$keywords%",
);
}
// other params
// .......
// query & send to view
$this->set('companies', $this->Company->find('list',
compact('conditions')));
}
}
How to make hasMany find() conditions properly?
Should I force join or use bindModel or a better way?
Side question 1: why Google indexes Cookbook 1.2 Collection, but not
1.3?
Side question 2: why CakePHP use '' for empty VARCHAR instead of NULL
and then NULL for empty INT?
Side question 3: is it planned to support MySQL YEAR?
Side question 4: is it better to use $order in Model or find()
$params['order']?
Ok, I have more questions, but that's for now.
Thank you for the answers. I really appreciate your time.
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
No comments:
Post a Comment