Skip to content

Instantly share code, notes, and snippets.

@ziplizard
Last active August 29, 2015 14:07
Show Gist options
  • Save ziplizard/0e22eb0202e81cded8aa to your computer and use it in GitHub Desktop.
Save ziplizard/0e22eb0202e81cded8aa to your computer and use it in GitHub Desktop.
belongsTo custom condition does not work
<?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
@ziplizard
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment