示例#1
0
文件: Map.php 项目: TuxBoy/Demo-saf
 /**
  * Gets sql elements for a mapping between two objects
  *
  * @example
  * list($table, $field1, $field2, $id1, $id2) = Sql_Map_Builder::sqlElementsOf( (...) );
  *
  * @param $object         object the source object
  * @param $property       Reflection_Property the property of the source object used for the mapping
  * @param $foreign_object object the mapped object
  * @return array
  */
 public static function sqlElementsOf($object, $property, $foreign_object)
 {
     // build table and fields
     $sql_link = new Link_Table($property);
     $table = $sql_link->table();
     $field1 = $sql_link->masterColumn();
     $field2 = $sql_link->foreignColumn();
     // build values
     $id1 = Dao::getObjectIdentifier($object, 'id');
     $id2 = Dao::getObjectIdentifier($foreign_object, 'id');
     // return elements
     return [$table, $field1, $field2, $id1, $id2];
 }
示例#2
0
文件: Joins.php 项目: TuxBoy/Demo-saf
 /**
  * @param $join               Join
  * @param $master_path        string
  * @param $foreign_path       string
  * @param $foreign_class_name string
  * @param $property           Reflection_Property
  * @param $reverse            boolean
  */
 private function addLinkedJoin(Join $join, $master_path, $foreign_path, $foreign_class_name, Reflection_Property $property, $reverse = false)
 {
     $link_table = new Link_Table($property);
     $linked_join = new Join();
     $linked_join->foreign_column = $reverse ? $link_table->foreignColumn() : $link_table->masterColumn();
     $linked_join->foreign_table = $link_table->table();
     $linked_join->master_column = 'id';
     $linked_join->mode = $join->mode;
     $this->joins[$foreign_path . '-link'] = $this->addFinalize($linked_join, $master_path ? $master_path : 'id', $foreign_class_name, $foreign_path, 1);
     $join->foreign_column = 'id';
     $join->master_column = $reverse ? $link_table->masterColumn() : $link_table->foreignColumn();
     $join->master_alias = $linked_join->foreign_alias;
     $this->linked_tables[$linked_join->foreign_table] = [$join->master_column, $linked_join->foreign_column];
 }