Reputation: 2029
I have hasMany defined in model for this find function below.
$model=Investor::model()->find('fname=? AND lname=?', array($fname, $lname)
Is there a way we can access the relational data in the view?
Upvotes: 0
Views: 587
Reputation: 5291
Yes. There are two ways:
To access via lazy loading (additional SQL queries) you shouldn't add anything to your find
and in the view you'll just use:
<?php foreach($model->relationName as $relatedModel):?>
// something
<?php endforeach ?>
Eager loading will get everything in a single SQL query so it's more efficient in most cases. View will stay the same. The part that's different is Investor::model()->with('relationName')->find(…
.
Upvotes: 2