Ejemplo n.º 1
0
	public function __construct($source, $dest, $options = null)
	{
		$this->source_class = get_class($source);

		if (isset($options['class_name']))
		{
			$this->dest_class = $options['class_name'];
		}
		else
		{
			$this->dest_class = \Inflector::classify($dest);
		}

		if (isset($options['foreign_key']))
		{
			$this->foreign_key = $options['foreign_key'];
		}
		else
		{
			$this->foreign_key = \Inflector::foreign_key($this->source_class);
		}

		if ( ! class_exists($this->dest_class))
		{
			$this->dest_class = '\\Model\\'.$this->dest_class;
		}

		if ( ! class_exists($this->source_class))
		{
			$this->source_class = '\\Model\\'.$this->source_class;
		}

		$this->options = $options;
	}
Ejemplo n.º 2
0
 public function __construct($source, $dest, $options = null)
 {
     parent::__construct($source, $dest, $options);
     // Belongs to has different foreign key from has_one/has_many so overwrite default
     // when it wasn't given
     if (empty($options['foreign_key'])) {
         $this->foreign_key = \Inflector::foreign_key($this->dest_class);
     }
 }
Ejemplo n.º 3
0
 public function __construct($source, $dest, $options = null)
 {
     $this->source_class = get_class($source);
     if (isset($options['class_name'])) {
         $this->dest_class = $options['class_name'];
     } else {
         $this->dest_class = \Inflector::classify($dest);
     }
     if (isset($options['foreign_key'])) {
         $this->foreign_key = $options['foreign_key'];
     } else {
         $this->foreign_key = \Inflector::foreign_key($this->source_class);
     }
     $namespace = (\Request::active() ? ucfirst(\Request::active()->module) : '') . '\\';
     if (class_exists($dest = $namespace . 'Model_' . $this->dest_class)) {
         $this->dest_class = $dest;
     }
     if (!class_exists($this->source_class)) {
         $this->source_class = 'Model_' . $this->source_class;
     }
     $this->options = $options;
 }
Ejemplo n.º 4
0
 public function join()
 {
     $dest_table = \Inflector::tableize($this->dest_class);
     $source_table = \Inflector::tableize($this->source_class);
     $source_inst = new $this->source_class();
     $dest_inst = new $this->dest_class();
     $columns = $dest_inst->get_columns();
     if (isset($dest_inst->table_name)) {
         $dest_table = $dest_inst->table_name;
     }
     if (!isset($this->options['through']) || !$this->options['through']) {
         $join = array('table' => $dest_table, 'type' => 'LEFT OUTER', 'on' => array($dest_table . '.' . $this->foreign_key, '=', $source_table . '.' . $source_inst->get_primary_key()));
     } else {
         $through_foreign_key = array_key_exists('through_foreign_key', $this->options) ? $this->options['through_foreign_key'] : \Inflector::foreign_key($this->dest_class);
         $join = array(array('table' => $this->options['through'], 'type' => 'LEFT OUTER', 'on' => array($this->options['through'] . '.' . $this->foreign_key, '=', $source_table . '.' . $source_inst->get_primary_key())), array('table' => $dest_table, 'type' => 'LEFT OUTER', 'on' => array($dest_table . '.' . $dest_inst->get_primary_key(), '=', $this->options['through'] . '.' . $through_foreign_key)));
     }
     return array(array($dest_table => $columns), $join);
 }
Ejemplo n.º 5
0
	public function __construct(&$source, $dest, $options = null)
	{
		parent::__construct($source, $dest, $options);
		$this->foreign_key = \Inflector::foreign_key($this->source_class);
	}