Saturday, January 9, 2010

Re: Selecting records that have hasmany child records.

Just for curiosity, have you tried retrieving the data from the other
end of the relationship - from the Offer side?

$this->Offer->find(
'all', array(
'contain' => array('Venue'),
'conditions' => array('Offer.end_date >' => $time)
)
);

Use $this->Venue->Offer->find( if you are in the venues controller!

Will the result be useful to you?
Enjoy,
John

On Jan 10, 4:22 am, "#2Will" <willjbar...@gmail.com> wrote:
> Hi Everyone, thanks very much for the replies.
>
> The sub query is the only one that worked for me.  I have the acts as
> containable statement in my app_model.  I think i need to move  the
> condition statement out of contains and into the main contains
> statement to limit the venue selection to venues with current offers.
> Is this possible?
>
> something like
> $venues_contained = $this->Venue->find('all', array(
>                 'conditions' => array("Offer.date_end >" => $time)
>             ));
>
> but that throws a Unknown column 'Offer.date_end' in 'where clause'
> error.. Is this posible or should i just use the sub query?
>
> Thanks again
>
> will.
>
> Dave
>
> On Jan 5, 3:00 pm, Hazem Mohamed <hazeim...@gmail.com> wrote:
>
> > You can use sub-queries to solve this problem something like
>
> > $venues_contained = $this->Venue->find('all', array('conditions' =>
> > array("Venue.id in (SELECT DISTINCT Offer.venue_id FROM offers as
> > Offer WHERE Offer.date_end > '$time')")));
>
> > But you will need to check and filter time if it is a user input. You
> > can use Sanitize::escape($time)

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate