S
S
slip312014-04-28 14:24:07
MySQL
slip31, 2014-04-28 14:24:07

How to query a MySQL (Yii) database?

I don’t understand something
We have 2 tables
Content (with fields `id` and `pagetitle` and `template`) and Values ​​(`contentid` and `value`)
contendid = id
We need to make a list `pagetitle`, `values1`, `values2` from two tables. After all it is possible to make one request.
Those. you need to do:
"Select all `pagetitle` where `template`=4 and by the same id select from Values ​​all values ​​that have contentid = id.content"
Accordingly, what to write in relations
(Content) return $this->hasMany( 'Values', ['id' => 'contentid'])
and (Values) return $this->hasOne('Content', ['contentid' => 'id']) , and in the query itself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vit, 2014-04-28
@fornit1917

Are you talking about Yii2? In Yii 1.x this was handled by the with statement:
Yii 2 should also have a similar eager loading. In any case, the joinWith function is there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question