josh Posted April 2, 2011 Share Posted April 2, 2011 Greetings, Thank you in advance for your help. In the blog regarding handling related models in Yii it is stated: "And that’s all you need to do to get this to work. The dropDownList() method creates a SELECT menu. It’s associated with the departmentId attribute of this Model. The drop-down menu’s data has to come from CHtml::listData(). That part of the code says to fetch every Department, and to use the department’s id value for the menu value and its name value for the visible label." This works perfectly! Thank you. My question is when viewing, managing or updating the record I would like the value to show the name and not number associated with the entry. I have tried modifying my my model regarding the public function relations() { return array( ); } But to no avail. Please help. Thank you. Link to comment Share on other sites More sharing options...
Larry Posted April 2, 2011 Share Posted April 2, 2011 Thanks for the nice words. First, you do need to have the proper relations identified in the Model. But then, it's just a matter of referring to $model->relation_name->property, which is probably $model->department->name in this case (this reference is in the View). Link to comment Share on other sites More sharing options...
josh Posted April 4, 2011 Author Share Posted April 4, 2011 Thank you Mr Ullman for your quick response. This should be simple and I apologize for my ignorance in this situation but I am simply not seeing my relation. MediaArchive is my main form. BibleDetails is a lookup table that is populating the dropdown list for the Bible field on the MediaArchive form. So in my MediaArchive form I established the following relation public function relations() { return array( 'Bible' => array(self::HAS_ONE, 'BibleDetails','BibleEnglish') ); } In BibleDetails I added this to my relations public function relations() { return array( 'BibleEnglish' => array(self::BELONGS_TO, 'MediaArchive','Bible') ); } and then in my _view.php for my MediaArchive form I inserted <?php echo CHtml::encode($model->Bible->BibleEnglish); ?> OK, after all the chuckles could you please advise. I am not understanding relations. Thank you! Link to comment Share on other sites More sharing options...
Larry Posted April 4, 2011 Share Posted April 4, 2011 You're welcome. I'm not sure I understand what the actual relationship is between MediaArchive (is that a Model, by the way?) and BibleDetails. Also, I suspect your View file should have $model->Bible->someBibleModelProperty. Link to comment Share on other sites More sharing options...
josh Posted April 12, 2011 Author Share Posted April 12, 2011 You're welcome. I'm not sure I understand what the actual relationship is between MediaArchive (is that a Model, by the way?) and BibleDetails. Also, I suspect your View file should have $model->Bible->someBibleModelProperty. Thank you! I might not be the fastest but my perseverance paid off. I took another look at my database and fixed my FKs and now everything works. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts