Last active
August 29, 2015 14:07
-
-
Save ziplizard/0e22eb0202e81cded8aa to your computer and use it in GitHub Desktop.
belongsTo custom condition does not work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// in LinkedinPerson | |
public $hasMany = array( | |
'LinkedinRecommendation' => array( | |
'className' => 'LinkedinRecommendation', | |
'foreignKey' => false, | |
'dependent' => true, | |
), | |
) | |
// in LinkedinRecommendation | |
public $belongsTo = array( | |
'LinkedinPerson' => array( | |
'className' => 'LinkedinPerson', | |
'foreignKey' => false, | |
'conditions' => array('LinkedinPerson.linkedin_id = LinkedinRecommendation.linkedin_id'), | |
), | |
); | |
// the find | |
$res = $this->LinkedinPerson->find('first', array('contain'=>array('LinkedinRecommendation'), 'conditions'=>array('LinkedinPerson.id'=>35))); | |
// have also tried | |
$res = $this->Person->find('first', array('contain'=>array('LinkedinPerson.LinkedinRecommendation'), 'conditions'=>array('LinkedinPerson.id'=>35))); | |
// but get error on relationship of LinkedinPerson to LinkedinRecommendation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CREATE TABLE
linkedin_recommendations
(id
int(11) NOT NULL AUTO_INCREMENT,created
datetime NOT NULL,modified
datetime NOT NULL,linkedin_id
varchar(80) DEFAULT NULL,recommendation_id
int(11) DEFAULT NULL,recommendation_type
varchar(80) DEFAULT NULL,recommendation_text
text,recommender_name
varchar(80) DEFAULT NULL,PRIMARY KEY (
id
),KEY
idx_linkedin_id
(linkedin_id
)) ENGINE=MyISAM AUTO_INCREMENT=46 DEFAULT CHARSET=utf8