2011-10-06 2 views
0

관계 모델을 얻으려면 어떻게해야합니까? (다음, 그 관계의 모델) 다음과 같은Yii의 다중 레벨 관계 및 모델

어쩌면 뭔가하지만 메신저 붙어 :

$model = Store::model()->findByPk($_GET['id']); 

$relation = $model->getMetaData(); 

$relation = $relation->relations; 

foreach($relation as $name=>$relation){ 

    $model_of_relation = ??; 

} 
+0

당신이 그 모델로하고 싶지? 당신은 $ model-> 관계를 사용할 수 있습니다, 당신의 관계 스펙 배열을 반환합니다. 그러면 어떤 관계를 사용하고 싶다면 $ model-> getRelated (relationName) – RusAlex

답변

1

는 다음과 같이하십시오 :

$model = Store::model()->findByPk($_GET['id']); 
foreach($model->relations as $relatedModel) { 
    $model_of_relation = $model->getRelated($relatedModel); 
    // ... Other processing of $model_of_relation ... 
} 
+0

메쏘드에서 ...이 테이블에있는 관계를 메타 데이터로부터 '발견'하고 싶을 수도 있습니다 ...? 그렇다면 데이터베이스를 살펴보고 Store 클래스의 relations() 함수를 재정의해야합니다. [link] (http://www.yiiframework.com/doc/guide/1.1/en/database.arr)를 참조하십시오. – DavidDraughn