Should a relation overwrite a column from a model?

I spent sometime debugging the following situation:

I have a Gallery model with 4 relations: cover, pictures and creator.

When I run something like $gallery = Gallery::model()->findAll(), I got an array of pictures inside $gallery, and an User object inside $gallery->creator.

But $gallery->cover is just an integer, containing the ID of the object that (I think) should be there.

I found that, when you have a column with the same name of the relation (I had Gallery.cover = Picture.id and a ‘cover’ relation), the attribute will contain the value, not the object.

Shouldn’t the object have a higher priority instead of the simple column value?

Or a config to change that, I don’t know… Correct me if I’m wrong, but tell me why haha

Thank you in advance (:

It is an expected behavior. I think it’ll be better to find another name for this relation, but you can use the next method: http://www.yiiframework.com/doc/api/1.1/CActiveRecord#getRelated-detail

Yes… You are probably right (=

That’s the method I was searching for, thank you :D

For your purposes you might find it easier to name your field ‘creator_id’ and your relation ‘creator’ so that you have no naming conflict and you can lazy load like:


echo $gallery->creator->name;