Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Dataprovider For Related Activerecord Models

$
0
0
Is there an easy way to construct a dataprovider that returns objects related to another object?

I'm basically looking for the simplest version of this function:
/**
 * @param CActiveRecord $model        The primary model whose relations the provider will retrieve
 * @param string        $relationName The name of the relation we want to retrieve
 * @return CActiveDataProvider Provider that returns the related models
 **/
public function getRelationProvider($model, $relationName);


I do not want to return an array of related objects. Some instances may have thousands of related objects and I'm concerned about performance issues. (Sidenote: is that a valid concern? Should I just use CArrayDataProvider?)

I have considered this solution but it seems somewhat complicated:
  • Parse the relation declaration into a criteria object
  • Merge that criteria with the DbCriteria of an instance of the related model
  • Construct a dataprovider using the updated instance


I'd like to avoid that if possible. Any ideas/patterns for solving this problem?

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>