Yii Framework Forum: Relational Query With Through - How To Get Indistinct Results - Yii Framework Forum

Jump to content

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

Relational Query With Through - How To Get Indistinct Results indistinct = opposite of distinct Rate Topic: -----

#1 User is offline   cappadochian 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 150
  • Joined: 02-January 11

Posted 11 January 2013 - 02:47 PM

Hi,

I'm using Relational Query with through.

My data is like so (in connecting table or "through" table):
id id1 id2
1  1   1
2  1   2
3  1   1

Yii shows only distinct results:
id id1 id2
1  1   1
2  1   2

how can all rows be retrieved? So I need the "indistinct" results. Is there an option or workaround to this?

Thanks a lot!
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,630
  • Joined: 04-March 10
  • Location:UK

Posted 11 January 2013 - 02:53 PM

Can you post the relation config?
0

#3 User is offline   cappadochian 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 150
  • Joined: 02-January 11

Posted 11 January 2013 - 02:58 PM

relations:
'relation' => array(self::HAS_MANY, 'targetModel', array('targetModelId' => 'id'), 'through' => 'connTable'),


controller:
$model = $this->loadModel($id, 'Model')->with('relation');


$model->relation;

gives back only 2 objects instead of 3.

as I see, a LEFT OUTER JOIN is used in this case. the query itself gives back 3 rows, so it's good. the problem is somewhere else. as I see, only the primary key of the target table is selected, and that's where a distinct effect can come into the picture.
somewhere inside a function that deals with the objects, there must be an unwanted (in this case) array_unique function I guess.
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