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:
[list=1]
[*]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
[/list]
I’d like to avoid that if possible. Any ideas/patterns for solving this problem?
I have controller for viewing any model, by pk, or list of pks, or scope, or list of scopes, or by relation from another model, etc.
For example if I click "related orderedProducts" I get list of 17 related items (depending on scenario and context view of model(s) can be modified).
There many models with many different relations + there will be new models in future, I don’t want to make changes every time. So I need realisation for general case.