php - Nested select with left join in yii ActiveRecord -
I have a few tables main table Then my request directly to the database looks like this: In model relationships it now appears: I want to clarify: I can only use ActiveRecord . I suggest you use this simple method contractors and a linked table in it
Address is , in which a certain type of address is
(1, 2, 3) . When it is necessary to do
LEFT JOIN ORDER BY type , because 1 or 1 of some situations can be used with 2 or 3 type of address, but sometimes the fields do not consist of field There are
type . I made a request that meets my needs, but can not create the same query in ActiveRecord
Select t.id, join from address.address contractor as t (address from address * address as address address address). = '' And address contractor_id = t.id where ((t.type = 'store') and ('t name'% name% 'or address.address' like '% name%')) Group TID < / code>
public function relation () {'addresses' = & gt; Array (auto: HAS_MANY, 'address',' contractor_id ',' on '= & gt; "address.address! =' '', 'Command' = & gt; 'address.type ASC'),}
$ criteria = new CDBC account; $ criteria- & gt; join = 'join left ( Address by Address * Address by address. Type) address as address! Address: = "" and address contractor_id = t.id '; $ criteria- & gt; condition = 't.type =: type and (like t.name: names or addresses.address: name)); $ criteria- & gt; params = [' type '= & gt; $ Type, 'name' = & gt; '%'. $ Name. '%']; $ Criterion-> group = 't.id'; $ model = contractor :: model () -> search ( All criteria);
Comments
Post a Comment