示例#1
0
 public function __construct($from, $name, array $config)
 {
     $this->name = $name;
     $this->model_from = $from;
     $this->model_to = array_key_exists('model_to', $config) ? $config['model_to'] : \Inflector::get_namespace($from) . 'Model_' . \Inflector::classify($name);
     $this->key_from = array_key_exists('key_from', $config) ? (array) $config['key_from'] : $this->key_from;
     $this->key_to = array_key_exists('key_to', $config) ? (array) $config['key_to'] : $this->key_to;
     $this->conditions = array_key_exists('conditions', $config) ? (array) $config['conditions'] : array();
     if (!empty($config['table_through'])) {
         $this->table_through = $config['table_through'];
     } else {
         $table_name = array($this->model_from, $this->model_to);
         natcasesort($table_name);
         $table_name = array_merge($table_name);
         $this->table_through = \Inflector::tableize($table_name[0]) . '_' . \Inflector::tableize($table_name[1]);
     }
     $this->key_through_from = !empty($config['key_through_from']) ? (array) $config['key_through_from'] : (array) \Inflector::foreign_key($this->model_from);
     $this->key_through_to = !empty($config['key_through_to']) ? (array) $config['key_through_to'] : (array) \Inflector::foreign_key($this->model_to);
     $this->cascade_save = array_key_exists('cascade_save', $config) ? $config['cascade_save'] : $this->cascade_save;
     $this->cascade_delete = array_key_exists('cascade_delete', $config) ? $config['cascade_delete'] : $this->cascade_delete;
     if (!class_exists($this->model_to)) {
         throw new \FuelException('Related model not found by Many_Many relation "' . $this->name . '": ' . $this->model_to);
     }
     $this->model_to = get_real_class($this->model_to);
 }
示例#2
0
 public function __construct($from, $name, array $config)
 {
     $this->name = $name;
     $this->model_from = $from;
     $this->model_to = array_key_exists('model_to', $config) ? $config['model_to'] : \Inflector::get_namespace($from) . 'Model_' . \Inflector::classify($name);
     $this->key_from = array_key_exists('key_from', $config) ? (array) $config['key_from'] : $this->key_from;
     $this->key_to = array_key_exists('key_to', $config) ? (array) $config['key_to'] : (array) \Inflector::foreign_key($this->model_from);
     $this->cascade_save = array_key_exists('cascade_save', $config) ? $config['cascade_save'] : $this->cascade_save;
     $this->cascade_delete = array_key_exists('cascade_save', $config) ? $config['cascade_save'] : $this->cascade_delete;
     if (!class_exists($this->model_to)) {
         throw new Exception('Related model not found by Has_Many relation "' . $this->name . '": ' . $this->model_to);
     }
 }
示例#3
0
 /**
  * Test for Inflector::foreign_key()
  *
  * @test
  */
 public function test_foreign_key_with_model_prefx()
 {
     $this->assertEquals('inflector_id', Inflector::foreign_key('Model_Inflector'));
 }
示例#4
0
 /**
  *  Test {@link Inflector::foreign_key()}
  */
 public function testForeign_key()
 {
     $this->assertEquals(Inflector::foreign_key('people'), 'people_id');
     $this->assertEquals(Inflector::foreign_key('queries'), 'queries_id');
 }
示例#5
0
 /**
  * Test for Inflector::foreign_key()
  *
  * @test
  */
 public function test_foreign_key()
 {
     $output = Inflector::foreign_key('Inflector');
     $expected = 'inflector_id';
     $this->assertEquals($expected, $output);
     $output = Inflector::foreign_key('Inflector', false);
     $expected = 'inflectorid';
     $this->assertEquals($expected, $output);
 }