コード例 #1
0
ファイル: Hasmany.php プロジェクト: openbuildings/jam
 /**
  * Generate a query to remove models from the association (without deleting them), for specific ids
  * @param  Jam_Model $model
  * @param  array     $ids
  * @return Database_Query
  */
 public function remove_items_query(Jam_Model $model, array $ids)
 {
     if (TRUE === $this->delete_on_remove or Jam_Association::DELETE === $this->delete_on_remove) {
         foreach (Jam::all($this->foreign_model)->where_key($ids) as $item) {
             $item->delete();
         }
         $query = NULL;
     } elseif ($this->delete_on_remove === Jam_Association::ERASE) {
         $query = Jam_Query_Builder_Delete::factory($this->foreign_model)->where(':primary_key', 'IN', $ids);
         if ($this->is_polymorphic()) {
             $query->value($this->polymorphic_key, NULL);
         }
     } else {
         $query = Jam_Query_Builder_Update::factory($this->foreign_model)->where(':primary_key', 'IN', $ids)->value($this->foreign_key, NULL);
         if ($this->is_polymorphic()) {
             $query->value($this->polymorphic_key, NULL);
         }
     }
     return $query;
 }
コード例 #2
0
ファイル: Hasmany.php プロジェクト: Konro1/pms
 /**
  * Generate a query to remove models from the association (without deleting them), for specific ids
  * @param  Jam_Model $model
  * @param  array     $ids
  * @return Database_Query
  */
 public function remove_items_query(Jam_Model $model, array $ids)
 {
     switch ($this->delete_on_remove) {
         case TRUE:
         case Jam_Association::DELETE:
             foreach (Jam::all($this->foreign_model)->where_key($ids) as $item) {
                 $item->delete();
             }
             $query = NULL;
             break;
         case Jam_Association::ERASE:
             $query = Jam_Query_Builder_Delete::factory($this->foreign_model)->where(':primary_key', 'IN', $ids);
             if ($this->is_polymorphic()) {
                 $query->value($this->polymorphic_key, NULL);
             }
             break;
         default:
             $query = Jam_Query_Builder_Update::factory($this->foreign_model)->where(':primary_key', 'IN', $ids)->value($this->foreign_key, NULL);
             if ($this->is_polymorphic()) {
                 $query->value($this->polymorphic_key, NULL);
             }
     }
     return $query;
 }
コード例 #3
0
ファイル: DeleteTest.php プロジェクト: Konro1/pms
 public function test_order_by()
 {
     $select = new Jam_Query_Builder_Delete('test_post');
     $select->order_by('test_post.test_author_id', 'DESC');
     $this->assertEquals('DELETE FROM `test_posts` ORDER BY `test_posts`.`test_author_id` DESC', (string) $select);
 }