I have a question about using the propel ORM and creating a query.
我有一个关于使用推进ORM和创建查询的问题。
I have a table "locations" with fields:
我有一个表“位置”与字段:
- location
- sublocation
- postcode
- street
- number
Now I want to select all the locations where the location field IS NOT equal to 'null'.
How can I do this? I've tried this but I get back all the results ...
现在我想选择位置字段不等于'null'的所有位置。我怎样才能做到这一点?我试过这个,但我收回了所有的结果......
Tried query: $locations = LocationQuery::create()->where('location' != null)->find();
尝试查询:$ locations = LocationQuery :: create() - > where('location'!= null) - > find();
4 个解决方案
#1
4
I don't know propel. But the proper SQL syntax for the expression would be:
我不知道推进。但是表达式的正确SQL语法是:
$locations = LocationQuery::create()->where('location is not null')->find();
Any comparison to NULL
in SQL returns NULL
, which is treated as false. With the exception of is null
and is not null
.
在SQL中与NULL的任何比较都返回NULL,将其视为false。除了null并且不为null。
#2
16
You can use this:
你可以用这个:
->filterByColumnName(null, Criteria::NOT_EQUAL)
There are various 'Criteria' uses in propel, listed here: propel criteria
推进中有各种“标准”用途,列于此处:推进标准
There isn't an exact sample for this on the site, the closest is this:
网站上没有相关的确切示例,最接近的是:
->filterByTags(array('novel', 'russian'), Criteria::CONTAINS_NONE)
#3
4
You can also use
你也可以使用
->filterByColumnName(null, CRITERIA::ISNOTNULL)
#4
0
You can reference all of the Propel 2 comparison types for CRITERIA::_needed_type_
here.
您可以在此处引用CRITERIA :: _ needed_type_的所有Propel 2比较类型。
EQUAL
NOT_EQUAL
ALT_NOT_EQUAL
GREATER_THAN
LESS_THAN
GREATER_EQUAL
LESS_EQUAL
LIKE
NOT_LIKE
CONTAINS_ALL
CONTAINS_SOME
CONTAINS_NONE
ILIKE
NOT_ILIKE
CUSTOM
RAW
CUSTOM_EQUAL
DISTINCT
IN
NOT_IN
ALL
JOIN
BINARY_AND
BINARY_OR
ASC
DESC
ISNULL
ISNOTNULL
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
LEFT_JOIN
RIGHT_JOIN
INNER_JOIN
LOGICAL_OR
LOGICAL_AND
#1
4
I don't know propel. But the proper SQL syntax for the expression would be:
我不知道推进。但是表达式的正确SQL语法是:
$locations = LocationQuery::create()->where('location is not null')->find();
Any comparison to NULL
in SQL returns NULL
, which is treated as false. With the exception of is null
and is not null
.
在SQL中与NULL的任何比较都返回NULL,将其视为false。除了null并且不为null。
#2
16
You can use this:
你可以用这个:
->filterByColumnName(null, Criteria::NOT_EQUAL)
There are various 'Criteria' uses in propel, listed here: propel criteria
推进中有各种“标准”用途,列于此处:推进标准
There isn't an exact sample for this on the site, the closest is this:
网站上没有相关的确切示例,最接近的是:
->filterByTags(array('novel', 'russian'), Criteria::CONTAINS_NONE)
#3
4
You can also use
你也可以使用
->filterByColumnName(null, CRITERIA::ISNOTNULL)
#4
0
You can reference all of the Propel 2 comparison types for CRITERIA::_needed_type_
here.
您可以在此处引用CRITERIA :: _ needed_type_的所有Propel 2比较类型。
EQUAL
NOT_EQUAL
ALT_NOT_EQUAL
GREATER_THAN
LESS_THAN
GREATER_EQUAL
LESS_EQUAL
LIKE
NOT_LIKE
CONTAINS_ALL
CONTAINS_SOME
CONTAINS_NONE
ILIKE
NOT_ILIKE
CUSTOM
RAW
CUSTOM_EQUAL
DISTINCT
IN
NOT_IN
ALL
JOIN
BINARY_AND
BINARY_OR
ASC
DESC
ISNULL
ISNOTNULL
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
LEFT_JOIN
RIGHT_JOIN
INNER_JOIN
LOGICAL_OR
LOGICAL_AND