keeb0
keeb0

Reputation: 1

How use "IS NOT NULL" in select() method of ActiveRecord in yii2?

Hi I have some table with column 'geom' which contain large data. When I make Model by this table I need select all columns without this 'geom' col. Wanna just check contain this col something or not and write true or false value of the col. Like this in SQL:

SELECT geom IS NOT NULL FROM tableName;

I tried this:

`$model = self::find()
        ->select(['([[geom]]) IS NOT NULL'])
        ->all();`

but it doesn't work.

Upvotes: 0

Views: 304

Answers (3)

Mahsa
Mahsa

Reputation: 383

You can use DB expression like follows:

$expression = new Expression('geom IS NOT NULL');
$model = self::find()
    ->select($expression)
    ->all()

Upvotes: 0

vvpanchev
vvpanchev

Reputation: 577

$model = self::find()
->select('geom')
->where(['NOT', ['geom' => null]])
->all();

Upvotes: 2

keeb0
keeb0

Reputation: 1

I solved it by this command:

$model = ClassName::findBySql('SELECT leshoz_ru, geom IS NOT NULL AS geom FROM leshoz')->all();

Upvotes: 0

Related Questions