/** * @codeCoverageIgnore */ public static function initialize(Jam_Meta $meta) { $meta->unique_key(function ($key) { return is_numeric($key) ? 'id' : 'identifier'; })->table('promotions')->associations(array('purchase_items' => Jam::association('hasmany', array('as' => 'reference', 'foreign_model' => 'purchase_item_promotion')), 'promo_codes' => Jam::association('hasmany', array('inverse_of' => 'promotion'))))->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'currency' => Jam::field('string'), 'identifier' => Jam::field('string'), 'description' => Jam::field('text'), 'priority' => Jam::field('integer', array('default' => 1)), 'model' => Jam::field('polymorphic'), 'created_at' => Jam::field('timestamp', array('format' => 'Y-m-d H:i:s', 'auto_now_create' => TRUE)), 'expires_at' => Jam::field('timestamp', array('format' => 'Y-m-d H:i:s'))))->validator('name', array('present' => TRUE))->validator('currency', array('currency' => TRUE)); }
/** * Convert :primary_key, :name_kay and :unique_key to their corresponding column names * @param string $attribute * @param Jam_Meta $meta * @param mixed $value * @return string */ public static function resolve_meta_attribute($attribute, Jam_Meta $meta, $value = NULL) { switch ($attribute) { case ':primary_key': $attribute = $meta->primary_key(); break; case ':name_key': $attribute = $meta->name_key(); break; case ':unique_key': $attribute = $meta->unique_key($value); break; } return $attribute; }