Yii Framework Forum: Having Many to Many presentation layer issues - Yii Framework Forum

Jump to content

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

Having Many to Many presentation layer issues Rate Topic: -----

#1 User is offline   fennellgb 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 02-April 10

Posted 26 April 2010 - 11:13 PM

I have a many to many relationship between two tables, I am using a middle table with a composite key to connect the two tables together via this code in the relations() area.

'Track'=>array(self::MANY_MANY,'track','xref_panel2track(panel_id, track_id)'),


In my view I have a simple "zii.widgets.CDetailView" that I am using to present the data. All the data is presented fine except for the Track information that is part of the MANY to MANY relationship. I have tried both using the array() process shown below and the simple format of just putting 'Track.name', neither work.
<?php $this->widget('zii.widgets.CDetailView', array(
	'data'=>$model,
	'attributes'=>array(
		'requestor.username',
		'name',
		'description_short',
		'description_long',
		'notes',
                array(
                    'label'=>'Track',
                    'type'=>'raw',
                    'value'=>$model->Track["name"],
                ),
		'panelType.name',
		'panelStatus.name',
		'submitted',
	),
)); ?>


I do a print_r($model->Track) and can see that the data is there but when I try and reference it I get "Not Set", which is the value used when the data is NULL. I am assuming that this has something to do with the data being a potential array since this is a MANY to MANY relationship, but for the life of me I can't find any solutions in all my searches.

From print_r($model->Track):
Array ( [id] => 9125f93c-50af-11df-942b-003048333d92 [name] => Comics [description] => Comics Track )


Any and all help is greatly appreciated as I am at a complete loss on what is wrong here.
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 27 April 2010 - 01:16 AM

Have you tryed $model->Track->name
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   fennellgb 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 02-April 10

Posted 27 April 2010 - 10:18 AM

View Postmdomba, on 27 April 2010 - 01:16 AM, said:

Have you tryed $model->Track->name


Yes, I think I have tried all possible values and really wondering if this is a 3 dimensional array instead of a 2D.
0

#4 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 27 April 2010 - 10:48 AM

If it's a many-many relation the 'name' of which result should be picked? Know what i mean?!

You could use
array(
'value'=>'$data->Track[0]->name',
'filter'=>false,
),

to pick the name of the first result (track) or you need to reduce all tracks into one string.

regards
0

#5 User is offline   fennellgb 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 02-April 10

Posted 27 April 2010 - 10:52 AM

View Postyoshi, on 27 April 2010 - 10:48 AM, said:

If it's a many-many relation the 'name' of which result should be picked? Know what i mean?!

You could use
array(
'value'=>'$data->Track[0]->name',
'filter'=>false,
),

to pick the name of the first result (track) or you need to reduce all tracks into one string.

regards

Ah, thank you so much, I new it was a 3D, just brain farted on how to get to it... Much appreciated... =D
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