Skip to content

Instantly share code, notes, and snippets.

@jaredhoyt
Created January 26, 2011 21:35
Show Gist options
  • Save jaredhoyt/797517 to your computer and use it in GitHub Desktop.
Save jaredhoyt/797517 to your computer and use it in GitHub Desktop.
Polymorphic - example usage
<?php
class AppModel extends Model {
function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
if (isset($this->hasMany['Note'])) {
$this->hasMany['Note']['conditions']['Note.class'] = $this->name;
$this->hasMany['Note']['foreignKey'] = 'foreign_id';
}
}
}
<?php
class Customer extends AppModel {
var $hasMany = array('Note');
}
<?php
class Note extends AppModel {
var $actsAs = array('Polymorphic.Polymorphic');
var $belongsTo = array('Customer');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment