I'm trying to create a flexible search form to search a database with
multple hasMany associations.
Here's the models:
Part->hasMany->Mbmodel
Part->hasMany->Signon
Mbmodel->belongsTo->Part
Signon->belongsTo->Part
The Mbmodel table contains field model, Signon table contains
signonstring. I'd like to be able to search by Mbmodels.model and
Signon.signonstring to find results which only match those fields
entered in search form.
Basically, I'd like to implement CakePhP code which emulates the
following SQL:
SELECT *
FROM
parts, mbmodels, signons
WHERE
mbmodels.model LIKE '%M6TBA%'
AND
mbmodels.part_id = parts.id
AND
signons.signonstring LIKE '%2a69k%'
AND
signons.part_id = parts.id
I've been able to implement code to search for Mbmodels.model:
if (!empty($this->data['Mbmodel']['model'])) {
$search_term = $this->data['Mbmodel']['model'];
$conditions['Mbmodel']['model'] = "LIKE %{$search_term}%";
$parts = $this->Mbmodel->findAll($conditions);
}
Or to search for Signon.signonstring:
if (!empty($this->data['Signon']['signonstring'])) {
$search_term = $this->data['Signon']['signonstring'];
$conditions['Signon']['signonstring'] = "LIKE %{$search_term}%";
$parts = $this->Signon->findAll($conditions);
}
Problem is I haven't been able to figure out how to implement
something which supports both Mbmodel.model AND Signon.signonstring.
Can anyone provide me some help?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---