Select all fields where fieldone is not null + Propel

I have a question about using ORM Propel and creating a query.

I have a "location" table with fields:

  • location

  • district
  • postcode
  • the street
  • number

Now I want to select all locations in which the location field is NOT NOT null.
How can i do this? I tried this, but I am returning all the results ...

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

+4
source share
4 answers

I dont know. But the correct SQL syntax for the expression would be the following:

 $locations = LocationQuery::create()->where('location is not null')->find(); 

Any comparison with NULL in SQL returns NULL , which is considered false. Except is null and is not null .

+4
source

You can use this:

 ->filterByColumnName(null, Criteria::NOT_EQUAL) 

Propel uses various "criteria" listed here: promotion criteria

There is no exact sample on this site closest to this:

 ->filterByTags(array('novel', 'russian'), Criteria::CONTAINS_NONE) 
+14
source

You can also use

 ->filterByColumnName(null, CRITERIA::ISNOTNULL) 
+3
source

You can reference all 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 
0
source

Source: https://habr.com/ru/post/1498712/


All Articles