Hi there, currently having troubles inside a fairly simple
preDqlSelect(), defined inside a record listener. I've followed the
Doctrine documentation, using the code below I'm getting a
Doctrine_Connection_Mysql_Exception that reads:
Column not found: 1054 Unknown column 'a.publish_until' in 'where
clause'
I've looked as hard as I can for schoolboy errors (which doesn't mean
there aren't any) but as far as I can see, I'm using the correct alias
up until the SQL is generated, at which time it *appears* the alias I
get changes in the original part of the query (the bits that come in
that I then tack onto with my where clause).
Here's the preDqlSelect(), couple of var_dumps() added at the end:
public function preDqlSelect(Doctrine_Event $event)
{
$params = $event->getParams();
$query = $event->getQuery();
$published_at = $params['alias'] . '.published_at';
$publish_until = $params['alias'] . '.publish_until';
if(!$query->contains($published_at) && !$query-
>contains($publish_until))
{
$clause = 'IF(%until% IS NULL, %at% <= NOW(), NOW() BETWEEN
%until% AND %at%)';
$clause = strtr($clause, array(
'%at%' => $published_at,
'%until%' => $publish_until,
));
$query->addWhere($clause);
}
var_dump($query->getDql());
var_dump($query->getSqlQuery());
}
So, the first var_dump() spits out:
' FROM BlogPost a WHERE a.slug = ? AND IF(a.publish_until IS NULL,
a.published_at <= NOW(), NOW() BETWEEN a.publish_until AND
a.published_at)'
Ok no surprises there as far as I can tell. The second var_dump()
spits out:
'SELECT b.id AS b__id, b.category_id AS b__category_id, b.title AS
b__title, b.teaser AS b__teaser, b.body AS b__body, b.published_at AS
b__published_at, b.publish_until AS b__publish_until, b.slug AS
b__slug, b.created_at AS b__created_at, b.updated_at AS b__updated_at
FROM blog_post b WHERE (b.slug = ? AND IF(a.publish_until IS NULL,
a.published_at <= NOW(), NOW() BETWEEN a.publish_until AND
a.published_at))'
Hang on! Where did all the 'b's come from!? I've tried following this
into the Doctrine core and I just can't find the issue. I've made a
glaring schoolboy error, right?
I'd be VERY grateful if somebody could steer me back onto the path on
this one.
Thanks
John
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" 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/symfony-users?hl=en