A
A
Artem Gribkov2014-01-13 14:44:58
Yii
Artem Gribkov, 2014-01-13 14:44:58

How to get all table fields except one using DAO Yii?

Good afternoon!
It is necessary to get a row from the table, but not with all the fields, but with the exception of the `users_id` field.
How to implement it correctly using DAO?
Tried with condition but no luck.

$access = Yii::app()->db->createCommand()
                                ->select('*')
                                ->from(self::tableName())
                                ->where('users_id=:id', array(':id'=>$userId))
                                ->condition('users_id NOT IN' . self::tableName())
                                ->queryRow();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Chernyshev, 2014-01-13
@jowee

1) list all required fields in select:

$access = Yii::app()->db->createCommand()
                                ->select('id, name, ...')
                                ->from(self::tableName())
                                ->where('users_id=:id', array(':id'=>$userId))
                                ->queryRow();

2) select all and do unset($access['users_id']):
$access = Yii::app()->db->createCommand()
                                ->select('*')
                                ->from(self::tableName())
                                ->where('users_id=:id', array(':id'=>$userId))
                                ->queryRow(true);
unset($access['users_id']);

I
Igor Yatsevich, 2014-01-13
@IgoNsk

And you definitely need it exactly as you write in the formulation of the question? What does the task look like in real life, i.e. what should be done at the level of business logic, not code?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question