E
E
Evgeny Startsev2015-06-26 01:26:47
Yii
Evgeny Startsev, 2015-06-26 01:26:47

Why is it necessary to be so perverted in Yii2?

There is a request that works without problems

$query = News::find()
    ->select(['{{%news}}.id as nid','{{%news}}.`name` as `nname`', 'SUBSTRING({{%news}}.`text`, 1, 256 ) AS `ntext`', '{{%news}}.date', '{{%category}}.`id` AS catid','{{%category}}.`name` AS catname'])
    ->leftJoin('{{%category}}', '{{%category}}.id = {{%news}}.category_id')
    ->where($where['where'], $where['arr']);

But I don't like that all fields need to be renamed....
Maybe there is a more rational way to link two tables?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2015-06-26
Protko @Fesor

aliases?
Because people can.

A
Andrey Klyuev, 2015-06-26
@BBird

And if you write a SQL query without a builder, won't you need to "rename the fields"?
Problem rather in "Why it is necessary so to be perverted in SQL?"
I don’t consider this a perversion myself, but I have come across such a solution: name fields in tables as news_id, news_name (in news) and category_id, category_name (in category). Well, in general, you understand, all fields are obtained with unique names;)

A
Alexander N++, 2015-06-26
@sanchezzzhak

https://github.com/yiisoft/yii2/blob/master/docs/g...
Relational hasOne
or keep doing a bunch>.<

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question