I used the Post and Tags model as an example
http://manual.cakephp.org/chapter/6

I have a Contacts model that are essentially associated to two types of
tags via a join table:

class Contact extends AppModel
{
    var $name = 'Contact';


        var $hasAndBelongsToMany = array('Market' =>
                               array('className'  => 'Market',
                                     'joinTable'  =>
'contacts_markets',
                                     'foreignKey' => 'contact_id',
                                     'associationForeignKey'=>
'market_id',
                                     'conditions' => '',
                                     'order'      => '',
                                     'limit'      => '',
                                     'uniq'       => true,
                                     'finderSql'  => '',
                                     'deleteQuery'=> 'DELETE FROM
contacts_markets, contacts WHERE contacts_markets.contact_id =
{$__cake_id__$} AND contacts.id = {$__cake_id__$}'),

                                                         'Propertytype'         
 =>
                       array('className'             => 'Propertytype',
                             'joinTable'             =>
'contacts_propertytypes',
                             'foreignKey'            => 'contact_id',
                             'associationForeignKey' =>
'propertytype_id',
                             'conditions'            => '',
                             'order'                 => '',
                             'uniq'                  =>  true,
                             'finderQuery'           => '',
                             'deleteQuery'           => 'DELETE FROM
contacts_propertytypes, contacts WHERE
contacts_propertytypes.contact_id = {$__cake_id__$} AND contacts.id =
{$__cake_id__$}',
                             'insertQuery'           => '')
                                                         );

        var $validate = array(

        'first_name'  => VALID_NOT_EMPTY,
        'last_name'   => VALID_NOT_EMPTY,
                'company_name' => VALID_NOT_EMPTY

    );
}


Everything with this setup works fine. I can select multiple items from
markets and propertytypes and they are saved with the Contact.

I am trying to build a search for Contacts based on Markets and
Propertytypes.

For instance I would like to return all Contacts that are in
Market1,Market4,Market5 and Propertytype6,PropertyType7.

I have setup hasAndBelongsToMany associations in my Propertytype and
Market models.

I have created a "query" function in my ContactsController but I am
having trouble trying to return Contacts that match all criteria.

Basically my query function takes the market_id's and
propertytype_id's, I then return Contacts for each criteria (ie
$this->Contact->Market->find("id=$val")). Then I intersect all the
arrays of results to match the criteria.

This mostly works but I wanted to know if there might be an easier way
w/ cake because my solution seems far from elegant.

Thanks In Advance for All the help and sorry for the long post. I try
to anticipate the information you might need.

Regards,
   Shinan


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

Reply via email to