Yii Framework Forum: Dataprovider Pagesize Problem With Related Models - Yii Framework Forum

Jump to content

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

Dataprovider Pagesize Problem With Related Models CListView not displaying all records and also not showing a pager Rate Topic: -----

#1 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 347
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 07 January 2013 - 02:44 AM

Hi guys.

In my model's search() function, I retrieve parent records and their related child records via "with" statements; and I also use "together = true".

I display these records in a CListView. The CListView's HTML looks like this (simplified):
<tr>
	<td>	<b>Parent Record Label</b>	</td>
	<td>	<p>Parent Record Data</p>	</td>
</tr>

<tr>
	<td>	<b>Child Record Heading</b> </td>
	<td>	<u>Label Column1</u> </td>
	<td>	<u>Label Column2</u> </td>
</tr>
		
<tr>
	<td>				
	</td>
	<td>
		<?php foreach ($data->relation_to_child_model as $child):?>
			<?php echo $child->data1; ?>	</br>
		<?php endforeach; ?>	
	</td>
	<td>
		<?php foreach ($data->relation_to_child_model as $child):?>
			<?php echo $child->data2; ?>	</br>
		<?php endforeach; ?>	
	</td>
</tr>

The result looks something like this:

Parent Record Label: _____ Parent Record Data
Child Record Heading: ____ Label Column1 ___ Label Column2
___________________________Child Data1 ______ Child Data2
___________________________Child Data1 ______ Child Data2

Parent Record Label: _____ Parent Record Data
Child Record Heading: ____ Label Column1 ___ Label Column2
___________________________Child Data1 ______ Child Data2
___________________________Child Data1 ______ Child Data2
___________________________Child Data1 ______ Child Data2
___________________________Child Data1 ______ Child Data2
___________________________Child Data1 ______ Child Data2



My problem is this:
Let's say the PageSize = 10 (in dataprovider generation in search() function).

If the data consists of 15 parent records, then CListView will display 10 records with a pager to allow the user to page to the remaining parent records - nothing wrong so far.

However, if the data consists of a parent record with 15 related child records, then CListView still only displays 10 of these records, but WITHOUT showing a pager to allow the user to page to the remaining child records.

Any ideas?

Many thanx.
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,086
  • Joined: 16-February 11
  • Location:Japan

Posted 07 January 2013 - 03:01 AM

I think you have to do the lazy loading of the related models.

Please check this wiki.
http://www.yiiframew..._many-relation/
0

#3 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 347
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 07 January 2013 - 03:02 AM

OK, it shows all the records if I take out "together = true". But then I can't sort the child records.

So I will have to figure out how to sort the related records in their own query.
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,086
  • Joined: 16-February 11
  • Location:Japan

Posted 07 January 2013 - 03:15 AM

<?php
$children = $data->relation_to_child_model(array(
    'order' => 'something ASC',
));
?>
<?php foreach ($children as $child):?>
	<?php echo $child->data1; ?>	</br>
<?php endforeach; ?>	
<?php foreach ($children as $child):?>
	<?php echo $child->data2; ?>	</br>
<?php endforeach; ?>	

0

#5 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 347
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 07 January 2013 - 08:20 AM

Thanx Softark

I got it working by incorporating the 'order' clause into the 'with' clause; and not using 'together=true'.

$criteria->with = array(
	'rel_to_child1' => array( 
		'with' => array(
			'rel_to_child2' => array(
				'with' => array(
					'rel_to_child3'=>array(
						'select'=>'child3_field',
						'order'=>'child3_field ASC'
					), 
					'rel_to_child4'=>array(
						'select'=>'child4_field'),
					),
				),
			),
		),
	);

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