public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'model' => Jam::field('polymorphic'))); }
public static function initialize(Jam_Meta $meta) { $meta->table('vocabularies')->name_key('name'); $meta->behaviors(array('paranoid' => Jam::behavior('paranoid', array()))); $meta->associations(array('terms' => Jam::association('hasmany', array('inverse_of' => 'vocabulary')))); $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'is_hidden' => Jam::field('boolean', array()), 'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), 'updated_at' => Jam::field('timestamp', array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s', 'label' => "Last edited")))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'file' => Jam::field('upload', array('server' => 'test_local')), 'file2' => Jam::field('upload', array('server' => 'test_local', 'path' => 'test/:model/:model:id')))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // All fields are aliased to different columns $meta->fields(array('id' => Jam::field('primary', array('column' => 'id-alias')), 'name' => Jam::field('string', array('column' => 'name-alias')), 'description' => Jam::field('string', array('column' => 'description-alias')))); }
/** * Automatically sets foreign to sensible defaults. * * @param string $model * @param string $name * @return void */ public function initialize(Jam_Meta $meta, $name) { parent::initialize($meta, $name); if (!$this->foreign_key) { $this->foreign_key = $name . '_id'; } if ($this->foreign_key === $name) { throw new Kohana_Exception('In association ":name" for model ":model" - invalid foreign_key name. Field and Association cannot be the same name', array(':model' => $this->model, ':name' => $name)); } $meta->field($this->foreign_key, Jam::field('integer', array_merge($this->_default_field_options, $this->field_options))); if ($this->is_polymorphic()) { if (!is_string($this->polymorphic)) { $this->polymorphic = $name . '_model'; } $meta->field($this->polymorphic, Jam::field('string', array('convert_empty' => TRUE))); } elseif (!$this->foreign_model) { $this->foreign_model = $name; } if ($this->count_cache) { if ($this->is_polymorphic()) { throw new Kohana_Exception('Cannot use count cache on polymorphic associations'); } if ($this->count_cache === TRUE) { $this->count_cache = Inflector::plural($this->model) . '_count'; } } }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_owner' => Jam::association('belongsto', array('foreign_model' => 'test_author', 'foreign_key' => 'test_owner_id')), 'test_featured_category' => Jam::association('hasone', array('foreign_model' => 'test_category')), 'test_posts' => Jam::association('hasmany', array('inverse_of' => 'test_blog', 'count_cache' => TRUE, 'dependent' => Jam_Association::DELETE)), 'test_categories' => Jam::association('hasmany', array('required' => TRUE, 'inverse_of' => 'test_blog')), 'test_tags' => Jam::association('manytomany', array()))); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'url' => Jam::field('weblink'), 'test_posts_count' => Jam::field('integer'))); }
public static function initialize(Jam_Meta $meta) { $meta->table('terms')->name_key('name'); $meta->behaviors(array('nested' => Jam::behavior('Nested'), 'sluggable' => Jam::behavior('Sluggable', array('uses_primary_key' => FALSE, 'auto_save' => FALSE, 'unique' => TRUE)))); $meta->associations(array('vocabulary' => Jam::association('belongsto', array('inverse_of' => 'terms')))); $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'is_hidden' => Jam::field('boolean', array()), 'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), 'updated_at' => Jam::field('timestamp', array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s')))); $meta->validator('name', array('present' => TRUE)); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_image' => Jam::association('belongsto', array('dependent' => Jam_Association::DELETE)))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_post' => Jam::association('hasone', array('inverse_of' => 'test_author')), 'test_posts' => Jam::association('hasmany'), 'test_blogs_owned' => Jam::association('hasmany', array('foreign_model' => 'test_blog', 'foreign_key' => 'test_owner_id')), 'test_categories' => Jam::association('hasmany'), 'test_position' => Jam::association('belongsto'), 'permission' => Jam::association('belongsto', array('foreign_model' => 'test_position', 'foreign_key' => 'test_position_id')))); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'password' => Jam::field('password'), 'email' => Jam::field('string'))); }
/** * Casts the returned value to a given type. * * @param mixed $value * @return mixed */ public function set(Jam_Validated $model, $value, $is_changed) { if (isset($this->cast)) { // Cast the value using the field type defined in 'cast' $value = Jam::field($this->cast)->set($value); } return $value; }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_holder' => Jam::association('belongsto', array('polymorphic' => TRUE)), 'test_copyright' => Jam::association('hasone', array('dependent' => Jam_Association::ERASE)), 'test_copyrights' => Jam::association('hasmany', array('dependent' => Jam_Association::ERASE)))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'file' => Jam::field('upload', array('delete_file' => TRUE)))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_post' => Jam::association('belongsto', array('conditions' => array('where' => array('test_post._approved_by', 'IS', NULL)), 'counter_cache' => TRUE, 'touch' => 'updated')), 'test_blogs' => Jam::association('manytomany', array('join_table' => 'test_blogs_test_tags')))); $meta->behaviors(array('sluggable' => Jam::behavior('sluggable', array('uses_primary_key' => FALSE, 'unique' => TRUE, 'slug' => 'Model_Test_Tag::_slug')))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->behaviors(array('nested' => Jam::behavior('nested'))); $meta->associations(array('test_blog' => Jam::association('belongsto', array('inverse_of' => 'test_categories')), 'test_posts' => Jam::association('manytomany'), 'test_author' => Jam::association('belongsto'))); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'is_featured' => Jam::field('boolean'))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_author' => Jam::association('belongsto'))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'url' => Jam::field('string'), 'email' => Jam::field('string'), 'description' => Jam::field('string'), 'amount' => Jam::field('integer'))); $meta->validator('name', array('present' => TRUE))->validator('name', 'email', 'url', array('count' => array('minimum' => 2)))->validator('email', array('format' => array('filter' => FILTER_VALIDATE_EMAIL)))->validator('url', array('format' => array('filter' => FILTER_VALIDATE_URL)))->validator('amount', array('numeric' => array('greater_than' => 10, 'less_than' => 100)))->validator('description', array('length' => array('between' => array(10, 1000))))->validator('name', array('format' => array('filter' => FILTER_VALIDATE_IP), 'if' => 'name_is_ip'))->validator('name', array('length' => array('minimum' => 2))); $meta->with_options(array('unless' => 'name_is_normal()'))->validator('name', array('format' => array('filter' => FILTER_VALIDATE_EMAIL))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->name_key('file'); $meta->behaviors(array('paranoid' => Jam::behavior('paranoid', array('field' => 'deleted')), 'sortable' => Jam::behavior('sortable', array('field' => 'position', 'scope' => 'group')), 'sluggable' => Jam::behavior('sluggable', array('auto_save' => TRUE)), 'tokenable' => Jam::behavior('tokenable', array('uppercase' => TRUE)))); $meta->associations(array('test_holder' => Jam::association('belongsto', array('polymorphic' => 'test_holder_type')))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'file' => Jam::field('string'), 'group' => Jam::field('string'))); $meta->validator('file', array('length' => array('minimum' => 4))); }
public function initialize(Jam_Meta $meta, $name) { parent::initialize($meta, $name); if ($this->_save_size) { $meta->field($name . '_width', Jam::field('integer'))->field($name . '_height', Jam::field('integer')); } if ($this->_dynamic_server) { $this->_dynamic_server = $this->_dynamic_server === TRUE ? $name . '_server' : $this->_dynamic_server; $meta->field($this->_dynamic_server, Jam::field('string', array('default' => $this->_server))); } $meta->field($name, Jam::field('upload', array('path' => $this->_path, 'thumbnails' => $this->_thumbnails, 'transformations' => $this->_transformations, 'server' => $this->_server, 'dynamic_server' => $this->_dynamic_server, 'save_size' => $this->_save_size, 'delete_file' => $this->_delete_file))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // Posts always load_with an author //$meta->load_with(array('test_author')); $meta->name_key('name'); $meta->associations(array('test_blog' => Jam::association('belongsto', array('inverse_of' => 'test_posts')), 'test_author' => Jam::association('belongsto', array()), 'test_tags' => Jam::association('hasmany', array('inverse_of' => 'test_post')), 'approved_by' => Jam::association('belongsto', array('foreign_model' => 'test_author', 'foreign_key' => '_approved_by')), 'test_images' => Jam::association('hasmany', array('as' => 'test_holder', 'dependent' => Jam_Association::DELETE)), 'test_cover_image' => Jam::association('hasone', array('as' => 'test_holder', 'foreign_model' => 'test_image', 'dependent' => Jam_Association::DELETE)), 'test_categories' => Jam::association('manytomany'))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'slug' => Jam::field('slug', array('unique' => TRUE)), 'status' => Jam::field('string', array()), 'created' => Jam::field('timestamp', array('auto_now_create' => TRUE)), 'updated' => Jam::field('timestamp', array('auto_now_update' => TRUE)))); // Set some custom validators $meta->validator('name', array('present' => TRUE, 'if' => 'slug')); }
/** * Initializes the behavior * * It sets the fields used in generating the slug * * @param Jam_Event $event the jam event for the behavior * @param Jam_Model $model The Jam_Model object on which the behavior is applies * @param string $name * @return void */ public function initialize(Jam_Meta $meta, $name) { parent::initialize($meta, $name); $meta->field('slug', Jam::field('slug')); if ($this->_unique) { $meta->validator('slug', array('unique' => $this->_unique)); } if (!$this->_slug) { $this->_slug = $this->_uses_primary_key ? 'Jam_Behavior_Sluggable::_uses_primary_key_pattern' : 'Jam_Behavior_Sluggable::_no_primary_key_pattern'; } if (empty($this->_pattern)) { $this->_pattern = $this->_uses_primary_key ? Jam_Behavior_Sluggable::ID_SLUG : Jam_Behavior_Sluggable::SLUG; } }
public function initialize(Jam_Meta $meta, $name) { parent::initialize($meta, $name); $this->_associations = (array) $this->_associations; $this->_fields = (array) $this->_fields; if (!$this->_parent) { $meta->field('is_frozen', Jam::field('boolean')); $meta->field('is_just_frozen', Jam::field('boolean', array('in_db' => FALSE))); } if ($this->_skippable) { $this->_skippable = is_string($this->_skippable) ? $this->_skippable : static::DEFAULT_SKIPPABLE_FIELD; $meta->field($this->_skippable, Jam::field('boolean', $this->_skippable_field_options)); } }
/** * @codeCoverageIgnore */ public static function initialize(Jam_Meta $meta) { $meta->behaviors(array('paranoid' => Jam::behavior('paranoid')))->associations(array('brand_refund' => Jam::association('belongsto', array('inverse_of' => 'items')), 'purchase_item' => Jam::association('belongsto', array('inverse_of' => 'refund_items'))))->fields(array('id' => Jam::field('primary'), 'amount' => Jam::field('price')))->validator('brand_refund', 'purchase_item', array('present' => TRUE)); }
public static function initialize(Jam_Meta $meta) { parent::initialize($meta); $meta->table('test_positions')->field('size', Jam::field('string')); }
public static function initialize(Jam_Meta $meta) { $meta->behaviors(array('shippable_brand' => Jam::behavior('shippable_brand')))->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
/** * @codeCoverageIgnore */ public static function initialize(Jam_Meta $meta) { parent::initialize($meta); $meta->table('shippings')->fields(array('width' => Jam::field('float', array('places' => 2)), 'height' => Jam::field('float', array('places' => 2)), 'depth' => Jam::field('float', array('places' => 2)), 'weight' => Jam::field('float', array('places' => 2))))->validator('width', 'height', 'depth', 'weight', array('present' => TRUE, 'numeric' => array('greater_than_or_equal_to' => 0))); }
/** * @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)); }
/** * @codeCoverageIgnore */ public function initialize(Jam_Meta $meta, $name) { parent::initialize($meta, $name); $meta->associations(array('shipping_address' => Jam::association('belongsto', array('foreign_model' => 'address', 'dependent' => Jam_Association::DELETE))))->fields(array('shipping_same_as_billing' => Jam::field('boolean', array('default' => TRUE)), 'shipping_required' => Jam::field('boolean', array('in_db' => FALSE))))->events()->bind('model.add_item', array($this, 'add_item')); }
public static function initialize(Jam_Meta $meta) { $meta->fields(array('q' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { $meta->behaviors(array('materializedpath' => Jam::behavior('materializedpath')))->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { $meta->associations(array('styles' => Jam::association('taxonomy_terms', array('vocabulary' => 'Styles')), 'types' => Jam::association('taxonomy_terms', array('vocabulary' => 'Types')))); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { $meta->db(Kohana::TESTING); $meta->behaviors(array('closuretable' => Jam::behavior('closuretable', array('children_dependent' => Jam_Association::DELETE))))->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
/** * @codeCoverageIgnore */ public static function initialize(Jam_Meta $meta) { $meta->name_key('number')->behaviors(array('tokenable' => Jam::behavior('tokenable', array('uppercase' => TRUE, 'field' => 'number')), 'paranoid' => Jam::behavior('paranoid')))->associations(array('purchase' => Jam::association('belongsto', array('inverse_of' => 'brand_purchases')), 'items' => Jam::association('hasmany', array('inverse_of' => 'brand_purchase', 'foreign_model' => 'purchase_item', 'delete_on_remove' => Jam_Association::DELETE, 'dependent' => Jam_Association::DELETE)), 'refunds' => Jam::association('hasmany', array('inverse_of' => 'brand_purchase', 'foreign_model' => 'brand_refund', 'delete_on_remove' => Jam_Association::DELETE, 'dependent' => Jam_Association::DELETE)), 'brand' => Jam::association('belongsto', array('inverse_of' => 'brand_purchases'))))->fields(array('id' => Jam::field('primary'), 'is_frozen' => Jam::field('boolean'), 'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), 'updated_at' => Jam::field('timestamp', array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s'))))->validator('purchase', 'brand', array('present' => TRUE)); }