Wednesday, November 26, 2008

Filter on BelongsTo relationship

Hi all,

i have 2 tables: competition, competition choices.

In my model the definitions are as follows:

Competition:
var $hasMany = array(
'CompetitionChoice' => array('className' => 'CompetitionChoice',
'foreignKey' => 'competition_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),

Competition_choices:

var $belongsTo = array(
'Competition' => array('className' => 'Competition',
'foreignKey' => 'competition_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);


Now I have a listing of competition choices and I have a filter form which
will filter the listings. Now I want to filter by the competition name but I
am not sure what to do.

In my competitions_choices controller, do I need to set a condition for the
paginate section as example:


$this->paginate = array(
'conditions' => array(

"competitions.name like '%".$competitionSearchParam."%'"
)
);


$this->set('competitionChoices', $this->paginate('CompetitionChoice',
$filter));

I tried this but it didn't I also tried the following:

$filter[] = "competitions.name like '%".$competitionSearchParam."%'";
$this->set('competitionChoices', $this->paginate('CompetitionChoice',
$filter));

This also didnt work. I am not sure how to search for the competition name
as its the table that is connected to the competition_choices table by
competition_id.

Please if anyone can help or send links or tell me where I am going wrong I
will be grateful.

Thanks in advance.
Angelo


--
View this message in context: http://www.nabble.com/Filter-on-BelongsTo-relationship-tp20697216p20697216.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
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: