php - Nested select with left join in yii ActiveRecord -


I have a few tables main table 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

Then my request directly to the database looks like this:

  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>  

In model relationships it now appears:

  public function relation () {'addresses' = & gt; Array (auto: HAS_MANY, 'address',' contractor_id ',' on '= & gt; "address.address! =' '', 'Command' = & gt; 'address.type ASC'),}   

I want to clarify: I can only use ActiveRecord .

I suggest you use this simple method

  $ 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

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -