I have two tables:
Locations and Sales.
Locations HAS_MANY Sales, and Sales BELONGS_TO Locations
public function getFiveLocationsBySales()
{
return Locations::model()->findall(
array(
'select'=>'t.name, t.id, (SELECT `name` FROM `owners` WHERE id = t.owner) AS owner ,(SELECT sales.sales FROM sales WHERE location = t.id ORDER BY date DESC LIMIT 1) AS sale',
'order'=>'sale DESC',
'limit'=>'5'
)
);
}
<?php $locations = $this->getFiveLocationsBySales(); ?>
<table>
<tr class="listHead">
<td>Owner</td>
<td>Location Name</td>
<td>Sales</td>
<td>Actions</td>
</tr>
<?php
foreach($locations as $location)
{
?>
<tr class="listRow">
<td><?php echo $location->owner; ?></td>
<td><?php echo $location->name; ?></td>
<td><?php echo $location->sale; ?></td>
<td><?php echo CHtml::link('View Details',array('franchisees/view/location','id'=>$location->id)); ?></td>
</tr>
<?php
}
?>
</table>
I am getting this error:
Property "Locations.sale" is not defined.