Yes, find conditions not a big problem, but how to join table with
hasMany association (AdImage, and AdvertComfort)? After that, i coud
set conditions

On Dec 15, 9:46 pm, Rob <webwe...@gmail.com> wrote:
> You shouldn't have any trouble doing this if you build your models
> correctly and choose the right conditions in your find statement in
> the controller.
>
> I personally tend to do this by building the SQL query that works, and
> then back coding the conditions into the controller (although I'm sure
> there are lots of ways to come up with the same thing.
>
> I would think you'd have something like the following (untested
> obviously):
>
>  $adverts = $this->Advert->find('all', 'conditions' => array( 'AND' =>
> array(
>                 'AdsAuto.year BETWEEN ? AND ?' => array($date1,
> $date2),
>                 '(select count(1) from ad_images AdImage where
> AdImage.advert_id = Advert.id > 0)',
>                 'AdvertComfort.option_id' => array(1,7,8)
>             );
>
> On Dec 14, 4:38 pm, dev <minde...@gmail.com> wrote:
>
> > Hey,
>
> > I'm trying to build find function for many days with no luck, please
> > help me guys.
>
> > Models:
>
> > mysql> DESCRIBE adverts;
> > +----------------+------------------------+------+-----+---------
> > +----------------+
> > | Field          | Type                   | Null | Key | Default |
> > Extra          |
> > +----------------+------------------------+------+-----+---------
> > +----------------+
> > | id
> > | user_id
> > | ad_category_id
> > | code
> > | valid
> > | bad
> > | created
> > +----------------+------------------------+------+-----+---------
> > +----------------+
>
> > mysql> DESCRIBE ads_autos;
> > +--------------------+------------------+------+-----+---------
> > +----------------+
> > | Field              | Type             | Null | Key | Default |
> > Extra          |
> > +--------------------+------------------+------+-----+---------
> > +----------------+
> > | id
> > | advert_id
> > | ad_manufacturer_id
> > | ad_model_id
> > | ad_type_id
> > | year
> > | ad_fueltype_id
> > | ad_door_id
> > | ad_colour_id
> > | capacity
> > | cilinders
> > | power
> > | ad_gearbox_id
> > | gears
> > | pricein
> > | priceout
> > | ta
> > | milage
> > | comment
> > | name
> > | phone
> > | email
> > | ad_country_id
> > | ad_city_id
> > +--------------------+------------------+------+-----+---------
> > +----------------+
>
> > mysql> DESCRIBE ad_images;
> > +-----------+------------------+------+-----+---------+----------------
> > +
> > | Field     | Type             | Null | Key | Default | Extra
> > |
> > +-----------+------------------+------+-----+---------+----------------
> > +
> > | id
> > | advert_id
> > | url
> > | created
> > +-----------+------------------+------+-----+---------+----------------
> > +
>
> > mysql> DESCRIBE advert_comfort;
> > +-----------+------------------+------+-----+---------+----------------
> > +
> > | Field     | Type             | Null | Key | Default | Extra
> > |
> > +-----------+------------------+------+-----+---------+----------------
> > +
> > | id
> > | advert_id
> > | option_id
> > +-----------+------------------+------+-----+---------+----------------
> > +
>
> > Models and associations:
>
> > Advert hasMany AdImage
> > Advert hasMany AdvertComfort
> > Advert hasOne AdsAuto
>
> > I need find function, when there are such conditions, for example:
>
> > AdsAuto.year from .. to ..
> > AdvertComfort.option_id is 1,7,8 ...
> > and Advert has at least one AdImage (photo)
>
> > I tried many ways with Containable, INNER JOIN but with no luck.  I
> > can't get all these conditions in one query, but i need to get Advert
> > model results if only all conditions are true.
>
> > P.S. sorry for my bad english
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to