示例#1
0
 /**
  * Allow for driver changes.
  */
 public function getPrimaryKey()
 {
     if ($this->getDriver() instanceof \Titon\Db\Mongo\MongoDriver) {
         return '_id';
     }
     return parent::getPrimaryKey();
 }
示例#2
0
 public function testDeleteWithManyToMany()
 {
     $this->loadFixtures(['Books', 'Genres', 'BookGenres']);
     $book = Book::select()->where('id', 5)->with('Genres')->first();
     $this->assertEquals(new Book(['id' => 5, 'series_id' => 1, 'name' => 'A Dance with Dragons', 'isbn' => '0-553-80147-3', 'released' => '2011-07-19', 'Genres' => new ModelCollection([new Genre(['id' => 3, 'name' => 'Action-Adventure', 'book_count' => 8, 'junction' => new Entity(['id' => 14, 'book_id' => 5, 'genre_id' => 3])]), new Genre(['id' => 5, 'name' => 'Horror', 'book_count' => 5, 'junction' => new Entity(['id' => 15, 'book_id' => 5, 'genre_id' => 5])]), new Genre(['id' => 8, 'name' => 'Fantasy', 'book_count' => 15, 'junction' => new Entity(['id' => 13, 'book_id' => 5, 'genre_id' => 8])])])]), $book);
     $this->assertEquals(1, $book->delete());
     $book = Book::find(5);
     $this->assertFalse($book->exists());
     // Related record is not deleted
     $genre = Genre::find(3);
     $this->assertEquals(new Genre(['id' => 3, 'name' => 'Action-Adventure', 'book_count' => 8]), $genre);
     // Junction records are deleted
     $repo = new Repository(['table' => 'books_genres']);
     $this->assertEquals(0, $repo->select()->where('book_id', 5)->count());
 }
示例#3
0
 public function testGetSchemaThroughDescribe()
 {
     $this->loadFixtures('Users');
     // Requires table to be created
     $repo = new Repository(['table' => 'users']);
     $schema = $repo->getSchema();
     $this->assertInstanceOf('Titon\\Db\\Driver\\Schema', $schema);
     $this->assertArraysEqual(['id', 'country_id', 'username', 'password', 'email', 'firstName', 'lastName', 'age', 'created', 'modified'], array_keys($schema->getColumns()));
 }
示例#4
0
文件: Model.php 项目: titon/model
 /**
  * {@inheritdoc}
  */
 public function setRepository(Repository $repository)
 {
     $repository->on('model', $this);
     foreach ($this->getRelations() as $relation) {
         $repository->on('relation', $relation);
     }
     $this->_repository = $repository;
     return $this;
 }