Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit FK mapping syntax for HAS_ONE not supported #49

Open
a9rolf-nb opened this issue Aug 29, 2014 · 1 comment
Open

Explicit FK mapping syntax for HAS_ONE not supported #49

a9rolf-nb opened this issue Aug 29, 2014 · 1 comment
Labels
Milestone

Comments

@a9rolf-nb
Copy link

To quote from the Yii AR documentation:

In case you need to specify custom PK->FK association you can define it as array('fk'=>'pk'). For composite keys it will be array('fk_c1'=>'pk_с1','fk_c2'=>'pk_c2').
(docblock in source)

Not talking about the composite key case here. Simply using the same syntax to explicitly name single foreign column => single local column.

If you have an AR child class with this:

// model's own primary key is (`nodeId`)

public function relations()
{
    return array(
        'parentRelationRecord' => array(
            self::HAS_ONE,
            'ProjectNodeParent',
            array('nodeId' => 'nodeId'),   // trivial case
        ),
        'status' => array(
            self::HAS_ONE,
            'Status',
            array('id' => 'statusId'),
        ),
    );
}

... saving triggers a PHP warning in EActiveRecordbehavior::afterSave Line #233

229    // update all not anymore related records
230    $criteria=new ECompositeDbCriteria();
231    $criteria->addNotInCondition(CActiveRecord::model($relation[1])->tableSchema->primaryKey, $newPKs);
232    // @todo add support for composite primary keys
233    $criteria->addColumnCondition(array($relation[2]=>$this->owner->getPrimaryKey()));

At this point, PHP is trying to use an array as an array key, which it can't. This causes the warning.
This call is initiated from CActiveRecord::afterSave and the event it triggers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants