Discussion:
findby not null
Darko Luketic
2013-04-13 07:43:37 UTC
Permalink
ORM
findby('game' => ?)

without using the querybuilder (because that's even more confusing)

http://docs.doctrine-project.org/en/latest/reference/working-with-associations.html#filtering-collections

It says "You can build expressions through the ExpressionBuilder"

Okay, but how, where?
Also IsNotNull isn't there in 2.4.0RC1 (in ExpressionBuilder)

And it's not the only criterion. The rest are default = expressions.

->findBy([
'voter' => $user,
'value' => 1,
'game' => criteria is not null
]);

I don't know wouldn't it be better if one could do something like this in
findBy?:
findBy([
'id' => [Expression::eq, 1],
'related' => $that,
'someothervalue' => [Expression::lt, 100],
'yaval' => 'somestring',
'ayaval' => [Expression::like, '%somestring']
])
so it checks if $value is an array and if it is replace the = with the new
expression.
foreach ($criteria as $key => $val)
{
if (!is_array($val))
{
// Expression is '='
}
else
{
// Expression is $val[0]
}
// rest
}

anyhow .. how do I findBy not null?
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to doctrine-user-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Jasper N. Brouwer
2013-04-13 09:23:40 UTC
Permalink
As far as I know the findBy and findOneBy can only use = and IN expressions (the latter when passing an array as value).

You'll have to use DQL to solve this. Just write a custom repository method to perform the query you want.
--
Jasper

(gestuurd vanaf mijn telefoon, dus kan wat kort en bondig zijn)
Post by Darko Luketic
ORM
findby('game' => ?)
without using the querybuilder (because that's even more confusing)
http://docs.doctrine-project.org/en/latest/reference/working-with-associations.html#filtering-collections
It says "You can build expressions through the ExpressionBuilder"
Okay, but how, where?
Also IsNotNull isn't there in 2.4.0RC1 (in ExpressionBuilder)
And it's not the only criterion. The rest are default = expressions.
->findBy([
'voter' => $user,
'value' => 1,
'game' => criteria is not null
]);
findBy([
'id' => [Expression::eq, 1],
'related' => $that,
'someothervalue' => [Expression::lt, 100],
'yaval' => 'somestring',
'ayaval' => [Expression::like, '%somestring']
])
so it checks if $value is an array and if it is replace the = with the new expression.
foreach ($criteria as $key => $val)
{
if (!is_array($val))
{
// Expression is '='
}
else
{
// Expression is $val[0]
}
// rest
}
anyhow .. how do I findBy not null?
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to doctrine-user-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Marco Pivetta
2013-04-13 12:06:20 UTC
Permalink
Just from the top of my head... I think this works also with the criteria
api (EntityRepository#select($criteria))
Post by Jasper N. Brouwer
As far as I know the findBy and findOneBy can only use = and IN
expressions (the latter when passing an array as value).
You'll have to use DQL to solve this. Just write a custom repository
method to perform the query you want.
--
Jasper
(gestuurd vanaf mijn telefoon, dus kan wat kort en bondig zijn)
ORM
findby('game' => ?)
without using the querybuilder (because that's even more confusing)
http://docs.doctrine-project.org/en/latest/reference/working-with-associations.html#filtering-collections
It says "You can build expressions through the ExpressionBuilder"
Okay, but how, where?
Also IsNotNull isn't there in 2.4.0RC1 (in ExpressionBuilder)
And it's not the only criterion. The rest are default = expressions.
->findBy([
'voter' => $user,
'value' => 1,
'game' => criteria is not null
]);
findBy([
'id' => [Expression::eq, 1],
'related' => $that,
'someothervalue' => [Expression::lt, 100],
'yaval' => 'somestring',
'ayaval' => [Expression::like, '%somestring']
])
so it checks if $value is an array and if it is replace the = with the new expression.
foreach ($criteria as $key => $val)
{
if (!is_array($val))
{
// Expression is '='
}
else
{
// Expression is $val[0]
}
// rest
}
anyhow .. how do I findBy not null?
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to doctrine-user-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Menno Holtkamp
2013-04-13 13:25:41 UTC
Permalink
Marco, the problem is the IS NOT NULL criteria, I also encountered this for
the IS NULL criteria, naively adding:

$criteria['property'] = null;

Did not work out. Like Jasper said, you need to write it down in DQL...

Would be nice to have a more accessible way using the $criteria array.

Cheers
Post by Marco Pivetta
Just from the top of my head... I think this works also with the criteria
api (EntityRepository#select($criteria))
Post by Jasper N. Brouwer
As far as I know the findBy and findOneBy can only use = and IN
expressions (the latter when passing an array as value).
You'll have to use DQL to solve this. Just write a custom repository
method to perform the query you want.
--
Jasper
(gestuurd vanaf mijn telefoon, dus kan wat kort en bondig zijn)
ORM
findby('game' => ?)
without using the querybuilder (because that's even more confusing)
http://docs.doctrine-project.org/en/latest/reference/working-with-associations.html#filtering-collections
It says "You can build expressions through the ExpressionBuilder"
Okay, but how, where?
Also IsNotNull isn't there in 2.4.0RC1 (in ExpressionBuilder)
And it's not the only criterion. The rest are default = expressions.
->findBy([
'voter' => $user,
'value' => 1,
'game' => criteria is not null
]);
findBy([
'id' => [Expression::eq, 1],
'related' => $that,
'someothervalue' => [Expression::lt, 100],
'yaval' => 'somestring',
'ayaval' => [Expression::like, '%somestring']
])
so it checks if $value is an array and if it is replace the = with the new expression.
foreach ($criteria as $key => $val)
{
if (!is_array($val))
{
// Expression is '='
}
else
{
// Expression is $val[0]
}
// rest
}
anyhow .. how do I findBy not null?
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to doctrine-user-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Marco Pivetta
2013-04-13 13:28:53 UTC
Permalink
I see... We could think of adding NULL and NOTNULL to
https://github.com/doctrine/collections/blob/master/lib/Doctrine/Common/Collections/Expr/Comparison.php#L30-L39eventually

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/
Post by Menno Holtkamp
Marco, the problem is the IS NOT NULL criteria, I also encountered this
$criteria['property'] = null;
Did not work out. Like Jasper said, you need to write it down in DQL...
Would be nice to have a more accessible way using the $criteria array.
Cheers
Post by Marco Pivetta
Just from the top of my head... I think this works also with the criteria
api (EntityRepository#select($criteria))
Post by Jasper N. Brouwer
As far as I know the findBy and findOneBy can only use = and IN
expressions (the latter when passing an array as value).
You'll have to use DQL to solve this. Just write a custom repository
method to perform the query you want.
--
Jasper
(gestuurd vanaf mijn telefoon, dus kan wat kort en bondig zijn)
ORM
findby('game' => ?)
without using the querybuilder (because that's even more confusing)
http://docs.doctrine-project.org/en/latest/reference/working-with-associations.html#filtering-collections
It says "You can build expressions through the ExpressionBuilder"
Okay, but how, where?
Also IsNotNull isn't there in 2.4.0RC1 (in ExpressionBuilder)
And it's not the only criterion. The rest are default = expressions.
->findBy([
'voter' => $user,
'value' => 1,
'game' => criteria is not null
]);
findBy([
'id' => [Expression::eq, 1],
'related' => $that,
'someothervalue' => [Expression::lt, 100],
'yaval' => 'somestring',
'ayaval' => [Expression::like, '%somestring']
])
so it checks if $value is an array and if it is replace the = with the new expression.
foreach ($criteria as $key => $val)
{
if (!is_array($val))
{
// Expression is '='
}
else
{
// Expression is $val[0]
}
// rest
}
anyhow .. how do I findBy not null?
--
You received this message because you are subscribed to the Google
Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google
Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to doctrine-user-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Menno Holtkamp
2013-04-13 13:32:03 UTC
Permalink
NULL would be ok, NOTNULL would introduce a new keyword as it would be of
type string in PHP right?
Post by Marco Pivetta
I see... We could think of adding NULL and NOTNULL to
https://github.com/doctrine/collections/blob/master/lib/Doctrine/Common/Collections/Expr/Comparison.php#L30-L39eventually
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
Post by Menno Holtkamp
Marco, the problem is the IS NOT NULL criteria, I also encountered this
$criteria['property'] = null;
Did not work out. Like Jasper said, you need to write it down in DQL...
Would be nice to have a more accessible way using the $criteria array.
Cheers
Post by Marco Pivetta
Just from the top of my head... I think this works also with the
criteria api (EntityRepository#select($criteria))
Post by Jasper N. Brouwer
As far as I know the findBy and findOneBy can only use = and IN
expressions (the latter when passing an array as value).
You'll have to use DQL to solve this. Just write a custom repository
method to perform the query you want.
--
Jasper
(gestuurd vanaf mijn telefoon, dus kan wat kort en bondig zijn)
ORM
findby('game' => ?)
without using the querybuilder (because that's even more confusing)
http://docs.doctrine-project.org/en/latest/reference/working-with-associations.html#filtering-collections
It says "You can build expressions through the ExpressionBuilder"
Okay, but how, where?
Also IsNotNull isn't there in 2.4.0RC1 (in ExpressionBuilder)
And it's not the only criterion. The rest are default = expressions.
->findBy([
'voter' => $user,
'value' => 1,
'game' => criteria is not null
]);
findBy([
'id' => [Expression::eq, 1],
'related' => $that,
'someothervalue' => [Expression::lt, 100],
'yaval' => 'somestring',
'ayaval' => [Expression::like, '%somestring']
])
so it checks if $value is an array and if it is replace the = with the
new expression.
foreach ($criteria as $key => $val)
{
if (!is_array($val))
{
// Expression is '='
}
else
{
// Expression is $val[0]
}
// rest
}
anyhow .. how do I findBy not null?
--
You received this message because you are subscribed to the Google
Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google
Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google
Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to doctrine-user-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Darko Luketic
2013-04-14 07:00:41 UTC
Permalink
Thank you for the replies.

DQL is indeed very handy and not as confusing as the QueryBuilder.

The question arose (for me) why I'd need an ORM when I have to write sql
for more complex things.
The answer is (for me) because it's more convenient when you get used to
it (and a big deal of it because of schema creation and update but also
the relations).
Post by Menno Holtkamp
Marco, the problem is the IS NOT NULL criteria, I also encountered
$criteria['property'] = null;
Did not work out. Like Jasper said, you need to write it down in DQL...
Would be nice to have a more accessible way using the $criteria array.
Cheers
Just from the top of my head... I think this works also with the
criteria api (EntityRepository#select($criteria))
As far as I know the findBy and findOneBy can only use = and
IN expressions (the latter when passing an array as value).
You'll have to use DQL to solve this. Just write a custom
repository method to perform the query you want.
--
Jasper
(gestuurd vanaf mijn telefoon, dus kan wat kort en bondig zijn)
Post by Darko Luketic
ORM
findby('game' => ?)
without using the querybuilder (because that's even more confusing)
http://docs.doctrine-project.org/en/latest/reference/working-with-associations.html#filtering-collections
It says "You can build expressions through the ExpressionBuilder"
Okay, but how, where?
Also IsNotNull isn't there in 2.4.0RC1 (in ExpressionBuilder)
And it's not the only criterion. The rest are default = expressions.
->findBy([
'voter' => $user,
'value' => 1,
'game' => criteria is not null
]);
I don't know wouldn't it be better if one could do something
findBy([
'id' => [Expression::eq, 1],
'related' => $that,
'someothervalue' => [Expression::lt, 100],
'yaval' => 'somestring',
'ayaval' => [Expression::like, '%somestring']
])
so it checks if $value is an array and if it is replace the =
with the new expression.
foreach ($criteria as $key => $val)
{
if (!is_array($val))
{
// Expression is '='
}
else
{
// Expression is $val[0]
}
// rest
}
anyhow .. how do I findBy not null?
--
You received this message because you are subscribed to the
Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from
it, send an email to
To post to this group, send email to
Visit this group at
http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the
Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from
it, send an email to
To post to this group, send email to
Visit this group at
http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google
Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it,
To post to this group, send email to
Visit this group at
http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the
Google Groups "doctrine-user" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/doctrine-user/-miqvEbL6L8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to doctrine-user-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/doctrine-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...