示例#1
0
 private static function insert_joined_record($class1, $class2)
 {
     $class2_assoc_name = Inflector::pluralize(Inflector::underscore(NimbleAssociation::class_as_string($class2)));
     $obj = NimbleAssociation::get_association_object($class1, $class2_assoc_name, 'has_and_belongs_to_many');
     $options = (array) $obj;
     $join_table = is_null($options['join_table']) ? NimbleAssociation::generate_join_table_name(array(strtolower(NimbleAssociation::class_as_string($class1)), strtolower(NimbleAssociation::class_as_string($class2)))) : $options['join_table'];
     $fk1 = is_null($options['foreign_key']) ? NimbleAssociation::foreign_key($class1) : $options['foreign_key'];
     $fk2 = is_null($options['association_foreign_key']) ? NimbleAssociation::foreign_key($class2) : $options['association_foreign_key'];
     static::execute("INSERT INTO {$join_table} ({$fk1}, {$fk2}) VALUES ('{$class1->id}', '{$class2->id}');");
 }
 public function __construct($class, $type, $arg)
 {
     if (!array_include($type, NimbleAssociation::$types)) {
         throw new NimbleRecordException('Invalid Association Type: ' . $type);
     }
     $this->type = $type;
     $this->class = NimbleAssociation::class_as_string($class);
     $this->name = $arg;
     foreach (static::$options[$this->type] as $var) {
         $this->{$var} = NULL;
     }
     return $this;
 }