Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed May 11, 2016
1 parent 532c3ec commit 02516de
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/FieldFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function mapRegex(array $map)
*
* @return self
*/
public function mapTypes(array $types)
public function mapTypes(array $map)
{
$this->mapTypes = $map + $this->mapTypes;

Expand Down
2 changes: 1 addition & 1 deletion src/Queries/Mysql/ExtendedSelectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function relatedWith(AbstractRow $row)
return $this->by($relation[1], $row->id);

case Scheme::HAS_MANY:
return $this->byId($relation[1], $row->{$relation[1]});
return $this->byId($row->{$relation[1]});

case Scheme::HAS_MANY_TO_MANY:
$this->from($relation[1]);
Expand Down
11 changes: 2 additions & 9 deletions src/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,6 @@ public function unrelateAll(Table $relationTable)
$this->{$relation[1]} = null;
$this->relations[$relationTable->name] = new NullValue();

$cache = $row->getCache();

if (isset($cache[$table->name])) {
unset($cache[$table->name][$this->id]);
$row->setCache($cache);
}

return $this->save();
}

Expand All @@ -383,8 +376,8 @@ public function unrelateAll(Table $relationTable)
->by($relation[2], $this->id)
->run();

unset($this->relations[$relation[1]]);
unset($this->relations[$relationTable->name][$row->id]);
$this->relations[$bridge->name] = $bridge->createCollection();
$this->relations[$relationTable->name] = $relationTable->createCollection();
}
}
}
2 changes: 1 addition & 1 deletion src/RowCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function __set($name, $value)
}

//Join the relations and rows
self::join($table, $this->rows, $row->getTable(), $row, $relation[1]);
self::join($table, $this->rows, $value->getTable(), $value, $relation[1]);
$this->loadedRelations[] = $name;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ protected function init()
/**
* Store a row in the cache.
*
* @param int $id
* @param Row $Row
* @param Row $row
*/
public function cache(Row $row)
{
Expand Down
11 changes: 9 additions & 2 deletions tests/RelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public function testRelatedQuery()
{
$db = $this->db;

$post = $db->post->create(['id' => 1]);
$comment = $db->comment->create(['id' => 1]);
$post = $db->post->create(['id' => 1])->save();
$comment = $db->comment->create(['id' => 1])->save();

$this->assertEquals(
'SELECT `category`.`id`, `category`.`name`, `category_post`.`post_id` FROM `category`, `category_post`, `post` WHERE (`category_post`.`category_id` = `category`.`id`) AND (`category_post`.`post_id` = `post`.`id`) AND (`post`.`id` IN (:post_id))',
Expand All @@ -69,6 +69,13 @@ public function testRelatedQuery()
(string) $post->comment()
);

$this->assertEquals(
'SELECT `post`.`id`, `post`.`title` FROM `post` WHERE (`post`.`id` IS NULL) LIMIT 1',
(string) $comment->post()
);

$comment->relate($post);

$this->assertEquals(
'SELECT `post`.`id`, `post`.`title` FROM `post` WHERE (`post`.`id` = :id) LIMIT 1',
(string) $comment->post()
Expand Down

0 comments on commit 02516de

Please sign in to comment.