| custom sql query [message #66371] |
Sun, 30 November 2008 05:08  |
yshaf13 Messages: 22 Registered: November 2008 |
Junior Member |
|
|
Hi, what would be the propel equivalent of this query?
(sf1.1)
select e.* from `event` e, `lecture` l where date(l.lecture_date) = date(e.event_date);
|
|
|
|
|
|
|
|
| Re: custom sql query [message #66652 is a reply to message #66398 ] |
Wed, 03 December 2008 16:14   |
GaryFx Messages: 377 Registered: May 2008 Location: Masschusetts |
Faithful Member |
|
|
| masterix wrote on Sun, 30 November 2008 15:40 |
$cr = new Criteria();
$cr->addJoin(EventPeer::EVENT_DATE, LecturePeer::LECTURE_DATE);
$cr->clearSelectColumns()->addSelectColumn(implode(',', array_values(EventPeer::getFieldNames(BasePeer::TYPE_COLNAME))));
|
There's no need to do the select columns.
If you don't select any columns, you will get all of the columns from the class used for the doSelect. So assuming this is evaluated with EventPeer::doSelect, you'll get the desired result.
To add the requested WHERE clause, use
$cr->add('DATE('.EventPeer::EVENT_DATE.')',
'DATE('.LecturePeer::LECTURE_DATE.')');
Aside: The use of $c for criteria is such a common convention in symfony that I'd really discourage alternatives such as $cr. A longer meaningful name can make sense (e.g. $lectureEventDatesCriteria), but $cr adds so little to $c that it may make a future maintainer hunting for a non-existent distinction.
|
|
|
| Re: custom sql query [message #66704 is a reply to message #66652 ] |
Wed, 03 December 2008 23:31  |
yshaf13 Messages: 22 Registered: November 2008 |
Junior Member |
|
|
Thanks for you're help.
| Quote: | $cr->add('DATE('.EventPeer::EVENT_DATE.')',
'DATE('.LecturePeer::LECTURE_DATE.')');
|
when i do that (and a doSelect) i get:
[wrapped: Cannot fetch TableMap for undefined table: DATE(event]
However
$cr->add(EventPeer::EVENT_DATE, 'date('.EventPeer::EVENT_DATE.')= date('.LecturePeer::LECTURE_DATE.')', Criteria::CUSTOM);
will work, problem is, I have to somehow select the Lecture table since I'm doing EventPeer::doSelect() (or else it will say undefined column Lecture_date), and if I do addSelectColumn(LectureDate::ID) it won't select anything else...
|
|
|