public static function initialize(Jelly_Meta $meta) { // Set database to connect to $meta->db(Unittest_Jelly_Testcase::$database_connection); // Define fields $meta->fields(array('id' => Jelly::field('primary'), 'name' => Jelly::field('string'), 'test_posts' => Jelly::field('manytomany'), 'parent' => Jelly::field('belongsto', array('foreign' => 'test_category', 'column' => 'parent_id')))); }
public static function initialize(Jelly_Meta $meta) { // Set database to connect to $meta->db(Unittest_Jelly_Testcase::$database_connection); // Define fields $meta->fields(array('id' => Jelly::field('primary'), 'name' => Jelly::field('string'), 'password' => Jelly::field('password'), 'email' => Jelly::field('email'), 'test_posts' => Jelly::field('hasmany'), 'test_post' => Jelly::field('hasone'), 'permission' => Jelly::field('belongsto', array('foreign' => 'test_role', 'column' => 'test_role_id')), '_id' => 'id')); }
public static function initialize(Jelly_Meta $meta) { // Set database to connect to $meta->db(Unittest_Jelly_Testcase::$database_connection); // Define fields $meta->fields(array('id' => Jelly::field('primary'), 'name' => Jelly::field('string'))); }
public static function initialize(Jelly_Meta $meta) { // Set database to connect to $meta->db(Unittest_Jelly_Testcase::$database_connection); // All fields are aliased to different columns $meta->fields(array('id' => Jelly::field('primary', array('column' => 'id-alias')), 'name' => Jelly::field('string', array('column' => 'name-alias')), 'description' => Jelly::field('string', array('column' => 'description-alias')), '_id' => 'id', '_name' => 'name', '_description' => 'description', '_bar' => 'foo')); }
public static function initialize(Jelly_Meta $meta) { // Set database to connect to $meta->db(Unittest_Jelly_Testcase::$database_connection); // Posts always load_with an author $meta->load_with(array('test_author')); // Set fields $meta->fields(array('id' => Jelly::field('primary'), 'name' => Jelly::field('string'), 'slug' => Jelly::field('slug', array('unique' => TRUE)), 'status' => Jelly::field('enum', array('choices' => array('draft', 'published', 'review'))), 'created' => Jelly::field('timestamp', array('auto_now_create' => TRUE)), 'updated' => Jelly::field('timestamp', array('auto_now_update' => TRUE)), 'test_author' => Jelly::field('belongsto'), 'test_categories' => Jelly::field('manytomany'), 'approved_by' => Jelly::field('belongsto', array('foreign' => 'test_author.id', 'column' => 'approved_by')), '_id' => 'id', '_slug' => 'slug')); }
/** * Tests various properties on a meta object. */ public function test_properties() { $fields = array('id' => new Jelly_Field_Primary(), 'id2' => new Jelly_Field_Primary(), 'name' => new Jelly_Field_String()); $meta = new Jelly_Meta(); $meta->db('foo')->table('foo')->builder('Jelly_Builder_Foo')->fields($fields)->fields(array('_id' => 'id2'))->sorting(array('foo' => 'bar'))->primary_key('id2')->name_key('name')->foreign_key('meta_fk')->load_with(array('test_post'))->behaviors(array(new Jelly_Behavior_Test()))->finalize('meta'); // Ensure the simple properties are preserved $expected = array('initialized' => TRUE, 'db' => 'foo', 'table' => 'foo', 'model' => 'meta', 'primary_key' => 'id2', 'name_key' => 'name', 'foreign_key' => 'meta_fk', 'builder' => 'Jelly_Builder_Foo', 'sorting' => array('foo' => 'bar'), 'load_with' => array('test_post')); foreach ($expected as $property => $value) { $this->assertSame($meta->{$property}(), $value); } // Ensure we can retrieve fields properly $this->assertSame($meta->field('_id'), $fields['id2']); $this->assertSame($meta->field('id2')->name, 'id2'); // Ensure all fields match $this->assertSame($meta->fields(), $fields); // Ensure defaults are set properly $this->assertSame($meta->defaults(), array('id' => NULL, 'id2' => NULL, 'name' => '')); foreach ($meta->behaviors() as $behavior) { // Ensure Behaviors return actual objects $this->assertTrue($behavior instanceof Jelly_Behavior); } }
public static function initialize(Jelly_Meta $meta) { // Notice how the MPTT fields are added automatically $meta->db('unit_testing')->table('jelly_mptt_owner')->fields = array('id' => new Field_Primary(), 'owned' => new Field_HasMany(array('foreign' => 'owned.owner_id'))); }
public static function initialize(Jelly_Meta $meta) { // Notice how the MPTT fields are added automatically $meta->db('unit_testing')->table('jelly_mptt_test')->fields = array('id' => new Field_Primary(), 'name' => new Field_String()); parent::initialize($meta); }