Answer the question
In order to leave comments, you need to log in
How to make ActiveRecord objects from QueryBuilder array?
Hello. The essence is that there are for example two tables:
TBL1
id|value|
TBL2
id|tbl1_id|value
When I get data by the Query class from the tbl2 table, an array of data is returned, but how can I get activerecord objects from this so that when I get data from tbl2 there is an array with an object from tbl1?
Answer the question
In order to leave comments, you need to log in
Create 2 models Tbl1 and Tbl2, write connections between them.
further, when we write this Tbl1::find()
, it returns a QueryBuilder, but all() and one() will already return the Tbl1 models. Tbl1::find()->with('tbl2')
will return the QueryBuilder already with a link if it was registered in the model and all(), one() will return Tbl1 and inside Tbl2 of the model.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question