I have the following query
UserLogin::model()
-> with(array(
'Provider'=> array(
'select'=>'name'
)
))
-> findAll(array(
'select' => 'count(t.id) as count ',
'group'=>'provider_id',
'order'=>'provider_id'
));
and my view is
<?php foreach($providerCounts as $providerCount): ?>
<tr>
<td><?php echo $providerCount['Provider']['name']; ?></td>
<td><?php echo $providerCount['count']; ?></td>
</tr>
<?php endforeach; ?>
Here is the relation
'Provider'=>array(self::BELONGS_TO, 'Provider', 'provider_id'),
I am getting the error
The same query in a different model is working.
Now i have two question
[list=1]
[*]Why is the query not working
[*]How do i debug such errors in yii
[/list]
Keith
(Kburton)
November 1, 2012, 7:09pm
2
Which line of code is the error referring to? I assume it’s not anything you’ve provided because that property isn’t mentioned in the code.
It looks like you’ve simply used the wrong property name somewhere.
It’s this
<?php echo $providerCount['count']; ?>
Keith
(Kburton)
November 1, 2012, 7:54pm
4
Okay, I think I see the issue.
If you’re going to use an attribute “count”, you need to create an instance variable to hold it.
At the top of the UserLogin class, put:
public $count;
What are you trying to achieve with this code though?
It worked … Why is this So … I have used same code in another model and there it works without public $count
Keith
(Kburton)
November 1, 2012, 8:00pm
6
I guess you’re not trying to populate an active record object with your other code. If you try to populate an active record from a query, all of the properties must exist in the class.