Home » Php » php – Select all fields where fieldone is not equal to null + Propel

php – Select all fields where fieldone is not equal to null + Propel

Posted by: admin July 12, 2020 Leave a comment

Questions:

I have a question about using the propel ORM and creating a query.

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 …

Tried query: $locations = LocationQuery::create()->where('location' != null)->find();

How to&Answers:

I don’t know propel. But the proper SQL syntax for the expression would be:

$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.

Answer:

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)

Answer:

You can also use

->filterByColumnName(null, CRITERIA::ISNOTNULL)

Answer:

You can reference all of the Propel 2 comparison types for CRITERIA::_needed_type_ here.

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