kkursor

Results 18 comments of kkursor

probably add RETURNING {$this->primaryKey()} to insert query. But this probably won't work on composite PK.

> Maybe we will use: RETURNING * > Also output inserted.* on mssql а фто, так можно было? век живи - век учись))) yeah, that's probably a solution. I'll check...

I've already read this. I knew about RETURNING field, but never noticed that one can use RETURNING *. That's probably a solution - after INSERT you may fill model object...

I've worked it around like this: ```php public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub if (true === $insert) { $this->id = Yii::$app->db->createCommand("SELECT currval('organizations_schema.organizations_id_seq'::regclass)")->queryScalar(); }...

Workaround seems to stop working. When I create an ActiveRecord in transaction, use my workaround to get id and try to modify and save model, I get weird save query....

changed crutch like @lluisclava wrote. ```php public function afterSave($insert, $changedAttributes) { if (true === $insert) { $id = Yii::$app->db->createCommand("SELECT currval('cafe_schema.cafes_static_id_seq'::regclass)")->queryScalar(); $this->id = $id; $this->setOldAttribute("id", $id); } return parent::afterSave($insert, $changedAttributes); ```...

It should be what I need if it didn't generate alias for this condition. It generates SELECT DISTINCT ON(short_name) AS short_name, * FROM materials. AS here is syntax error in...

That's full output of this example. ```sql Exception (Database Exception) 'yii\db\Exception' with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "AS" LINE 1: SELECT distinct on (short_name)...

It seems to work better. Though it doesn't distinct (row count is the same as without distinct condition), there is no syntax error. BTW select(['distinct on (short_name) *']) works too....