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

$association['foreignKey'] === false not supported #1

Open
korcan opened this issue Oct 21, 2010 · 1 comment
Open

$association['foreignKey'] === false not supported #1

korcan opened this issue Oct 21, 2010 · 1 comment

Comments

@korcan
Copy link

korcan commented Oct 21, 2010

Linkable does not support defining an alternative join not using the primary key. Linkable should allow setting foreign key to false to alternatively define the relationship, see below:
(http://stackoverflow.com/questions/3814862/cakephp-model-relation)
public $hasOne = array(
'RelatedModel' => array(
'className' => 'RelatedModel',
'foreignKey' => false,
'conditions' => array(
'MainModel.random_field = RelatedModel.some_field'
)
)
}

@korcan
Copy link
Author

korcan commented Oct 21, 2010

HERE IS THE PATCH:

See line 84 and the changes below...

                     $_Model->unbindModel(array('belongsTo' => array($Reference->alias)));
                 }
                 if (empty($options['conditions'])) {
                     if ($association['foreignKey'] === false) {
                        $options['conditions'] = $association['conditions'];
                     } elseif ($type === 'belongsTo') {
                         $modelKey = $_Model->escapeField($association['foreignKey']);
                         $referenceKey = $Reference->escapeField($Reference->primaryKey);
                         $options['conditions'] = "{$referenceKey} = {$modelKey}";

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

No branches or pull requests

1 participant