Skip to content

Instantly share code, notes, and snippets.

@meotimdihia
Created October 11, 2010 12:55
Show Gist options
  • Save meotimdihia/620472 to your computer and use it in GitHub Desktop.
Save meotimdihia/620472 to your computer and use it in GitHub Desktop.
class Article extends ArticlesAppModel {
var $belongsTo = array(
'ArticlesCategory' => array(
'className' => 'Articles.ArticlesCategory',
'foreignKey' => 'articles_category_id'
)
, 'User');
var $hasOne = array('Avatar' => array('className' => 'Image', 'foreignKey' => 'model_id', 'conditions' => array('Avatar.type' => 'hasOne', 'Avatar.model' => 'Article')));
}
class CommentableBehavior extends ModelBehavior {
public function setup(&$model, $settings = array()) {
if (!isset($this->settings[$model->alias])) {
$this->settings[$model->alias] = $this->defaults;
}
$this->settings[$model->alias] = am($this->settings[$model->alias], ife(is_array($settings), $settings, array()));
$cfg = $this->settings[$model->alias];
$model->bindModel(array('hasMany' => array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'foreign_key',
'unique' => true,
'conditions' => '',
'fields' => '',
'dependent' => true,
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''))), false);
$model->Comment->bindModel(array('belongsTo' => array(
$model->name => array(
'className' => $model->name,
'foreignKey' => 'foreign_key',
'unique' => true,
'conditions' => '',
'fields' => '',
'counterCache' => true,
'dependent' => false))), false);
$model->Comment->bindModel(array('belongsTo' => array(
$cfg['userModelAlias'] => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'counterCache' => true,
'order' => ''))), false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment