Retrieve Attributes of Joined Model?

I’ve got this in my actionUpdate and actionCreate

$prodefs = ExtraFields::model()->with(array('extraFieldValues'=>array('joinType'=>'LEFT OUTER JOIN')))->findAll();

The problem is I can’t seem to retrieve the attributes of the extraFieldValues referenced model in _form.php, did a var_dump and the attributes (which should have no value, currently) are not there. I think the problem is that the joined table is empty, but that shouldn’t be a problem with an outer join?

I need a hint

So you want to create or update a model with HAS_MANY related models in a single form.

Or, do you want to create or update multiple instances of model with HAS_MANY related models?

I’m not sure.

Could you elaborate your action a little more?

One thing you should note is that the related attribute is not automatically created when you have created an instance of model.

You can access the related model instances when you have loaded a model from db.

    $model = ExtraFields::model()->findByPk($id);

    $rel_models = $model->extraFieldValues;

This is OK. $rel_models will be an array of ExtraFieldValues. Though it can be an array of zero length, it is an array.

But when you have created an model instance, the things are different.

    $model = new ExtraFields;

    $rel_models = $model->extraFieldValues;

This is NG. $rel_models will be null, or ‘$model->extraFieldValues’ will throw an exception. I forgot which.

So you need to write substantially different codes to get the model instances for the form depending on which action you are working with, create or update.

Ok, I thought I was doing something wrong I can stop banging my head against the wall











To generalize

Doing this query

SELECT * FROM tbl_extra_fields LEFT OUTER JOIN tbl_extra_field_values ON tbl_extra_fields.extra_field_id = tbl_extra_field_values.extra_field_id

Would end up with the joined rows, although they have a null value they would be accessible.

Thanks a bunch.