Yii Framework Forum: How To Get Relation With Multiple Fields To Table Relation? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Get Relation With Multiple Fields To Table Relation?

#1 User is offline   zinzin day 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 27-December 10

Posted 06 September 2013 - 06:14 AM

Quote

Table A (tableName tbl_a, Model class Name is ModelA)
constructor: id, title
data: [{1,'title1'},{2,'title2'},{3,'title3'},{4,'title4'}]
Table B (tableName tbl_b, Model class Name is ModelB)
constructor: a_id1, a_id2
data: [{1,2},{1,3},{4,1},{3,2}]



    public function getRA1()
    {
        return $this->hasMany('ModelA', array('id' => 'aid2'))->viaTable('tbl_b', array('aid1' => 'id'));
    }
//get result [{1,'title1'},{3,'title3}]
    public function getRA2()
    {
        return $this->hasMany('ModelA', array('id' => 'aid1'))->viaTable('tbl_b', array('aid2' => 'id'));
    }
//get result [{4,'title4'}]


i want to merge two relations to one relation with condition tbl_a.id=tbl_b.aid1 and tbl_a.id = tbl_b.aid2
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,875
  • Joined: 04-October 08
  • Location:DC, USA

Posted 06 September 2013 - 07:31 AM

Answered in https://github.com/y...yii2/issues/851
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users