Skip to content

Commit a35d447

Browse files
committed
Bugfix: updated inner delimiter from "." to "---" for sqlite support
1 parent c0207f6 commit a35d447

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

CHANGELOG

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2014-11-13, v1.0.3
5+
------------------
6+
7+
* Bugfix: updated inner delimiter from "." to "---" for sqlite support
8+
49
2014-11-13, v1.0.2
510
------------------
611

src/SleepingOwl/WithJoin/WithJoinEloquentBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function addNestedRelations($name, Relation $relation)
6464
foreach ($nestedRelations as $nestedName => $nestedConstraints)
6565
{
6666
$relation = $class->$nestedName();
67-
$this->addJoinToQuery($nestedName, $name, $relation, $name . '.' . static::$prefix);
67+
$this->addJoinToQuery($nestedName, $name, $relation, $name . '---' . static::$prefix);
6868
}
6969
}
7070

@@ -94,7 +94,7 @@ protected function addJoinToQuery($joinTableAlias, $currentTableAlias, Relation
9494
$this->query->leftJoin($joinTable, $joinLeftCondition, '=', $joinRightCondition);
9595

9696
$columns = $this->getColumns($joinTableName);
97-
$prefix = static::$prefix . $columnsPrefix . $joinTableAlias . '.';
97+
$prefix = static::$prefix . $columnsPrefix . $joinTableAlias . '---';
9898
foreach ($columns as $column)
9999
{
100100
$this->selectFromQuery($joinTableAlias, $column, $prefix . $column);

src/SleepingOwl/WithJoin/WithJoinTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function newFromBuilder($attributes = [])
2121
{
2222
unset($attributes[$key]);
2323
$key = substr($key, strlen($prefix));
24+
$key = str_replace('---', '.', $key);
2425
Arr::set($foreignData, $key, $value);
2526
}
2627
}

tests/WithJoinEloquentBuilderTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function it_replaces_subqueries_with_left_join_using_references()
7575
$this->assertEquals('First Foo First Baz Bar', $bar->title);
7676
$this->assertEquals('First Foo', $bar->foo->title);
7777

78-
$this->assertQuery('select "foo"."id" as "__f__foo.id", "foo"."title" as "__f__foo.title", "foo"."created_at" as "__f__foo.created_at", "foo"."updated_at" as "__f__foo.updated_at", "bars".* from "bars" left join "foos" as "foo" on "foo"."id" = "bars"."foo_id" where "bars"."id" = ? limit 1');
78+
$this->assertQuery('select "foo"."id" as "__f__foo---id", "foo"."title" as "__f__foo---title", "foo"."created_at" as "__f__foo---created_at", "foo"."updated_at" as "__f__foo---updated_at", "bars".* from "bars" left join "foos" as "foo" on "foo"."id" = "bars"."foo_id" where "bars"."id" = ? limit 1');
7979

8080
$this->assertQueryCount(1);
8181
}
@@ -87,7 +87,7 @@ public function it_replaces_subqueries_with_left_join_using_includes()
8787
$this->assertEquals('First Foo First Baz Bar', $bar->title);
8888
$this->assertEquals('First Foo', $bar->foo->title);
8989

90-
$this->assertQuery('select "foo"."id" as "__f__foo.id", "foo"."title" as "__f__foo.title", "foo"."created_at" as "__f__foo.created_at", "foo"."updated_at" as "__f__foo.updated_at", "bars".* from "bars" left join "foos" as "foo" on "foo"."id" = "bars"."foo_id" where "bars"."id" = ? limit 1');
90+
$this->assertQuery('select "foo"."id" as "__f__foo---id", "foo"."title" as "__f__foo---title", "foo"."created_at" as "__f__foo---created_at", "foo"."updated_at" as "__f__foo---updated_at", "bars".* from "bars" left join "foos" as "foo" on "foo"."id" = "bars"."foo_id" where "bars"."id" = ? limit 1');
9191

9292
$this->assertQueryCount(1);
9393
}
@@ -99,7 +99,7 @@ public function it_joins_table_by_relation_name_as_alias()
9999
$this->assertEquals('First Foo First Baz Bar', $bar->title);
100100
$this->assertEquals('First Foo', $bar->foo->title);
101101

102-
$this->assertQuery('select "foo"."id" as "__f__foo.id", "foo"."title" as "__f__foo.title", "foo"."created_at" as "__f__foo.created_at", "foo"."updated_at" as "__f__foo.updated_at", "bars".* from "bars" left join "foos" as "foo" on "foo"."id" = "bars"."foo_id" where "foo"."id" = ? limit 1');
102+
$this->assertQuery('select "foo"."id" as "__f__foo---id", "foo"."title" as "__f__foo---title", "foo"."created_at" as "__f__foo---created_at", "foo"."updated_at" as "__f__foo---updated_at", "bars".* from "bars" left join "foos" as "foo" on "foo"."id" = "bars"."foo_id" where "foo"."id" = ? limit 1');
103103

104104
$this->assertQueryCount(1);
105105
}
@@ -112,7 +112,7 @@ public function it_support_multiple_flat_joins()
112112
$this->assertEquals('First Foo', $bar->foo->title);
113113
$this->assertEquals('Second Baz', $bar->baz->title);
114114

115-
$this->assertQuery('select "foo"."id" as "__f__foo.id", "foo"."title" as "__f__foo.title", "foo"."created_at" as "__f__foo.created_at", "foo"."updated_at" as "__f__foo.updated_at", "baz"."id" as "__f__baz.id", "baz"."title" as "__f__baz.title", "baz"."created_at" as "__f__baz.created_at", "baz"."updated_at" as "__f__baz.updated_at", "bars".* from "bars" left join "foos" as "foo" on "foo"."id" = "bars"."foo_id" left join "bazs" as "baz" on "baz"."id" = "bars"."baz_id" where "foo"."id" = ? and "baz"."id" = ? limit 1');
115+
$this->assertQuery('select "foo"."id" as "__f__foo---id", "foo"."title" as "__f__foo---title", "foo"."created_at" as "__f__foo---created_at", "foo"."updated_at" as "__f__foo---updated_at", "baz"."id" as "__f__baz---id", "baz"."title" as "__f__baz---title", "baz"."created_at" as "__f__baz---created_at", "baz"."updated_at" as "__f__baz---updated_at", "bars".* from "bars" left join "foos" as "foo" on "foo"."id" = "bars"."foo_id" left join "bazs" as "baz" on "baz"."id" = "bars"."baz_id" where "foo"."id" = ? and "baz"."id" = ? limit 1');
116116

117117
$this->assertQueryCount(1);
118118
}
@@ -125,7 +125,7 @@ public function it_can_combine_with_and_joins()
125125
$this->assertEquals('First Foo', $bar->foo->title);
126126
$this->assertEquals('Second Baz', $bar->baz->title);
127127

128-
$this->assertQuery('select "baz"."id" as "__f__baz.id", "baz"."title" as "__f__baz.title", "baz"."created_at" as "__f__baz.created_at", "baz"."updated_at" as "__f__baz.updated_at", "bars".* from "bars" left join "bazs" as "baz" on "baz"."id" = "bars"."baz_id" where "baz"."id" = ? limit 1');
128+
$this->assertQuery('select "baz"."id" as "__f__baz---id", "baz"."title" as "__f__baz---title", "baz"."created_at" as "__f__baz---created_at", "baz"."updated_at" as "__f__baz---updated_at", "bars".* from "bars" left join "bazs" as "baz" on "baz"."id" = "bars"."baz_id" where "baz"."id" = ? limit 1');
129129
$this->assertQuery('select * from "foos" where "foos"."id" in (?)');
130130

131131
$this->assertQueryCount(2);
@@ -139,7 +139,7 @@ public function it_supports_nested_relations()
139139
$this->assertEquals('First Foo First Baz Bar', $bom->bar->title);
140140
$this->assertEquals('First Foo', $bom->bar->foo->title);
141141

142-
$this->assertQuery('select "bar"."id" as "__f__bar.id", "bar"."title" as "__f__bar.title", "bar"."foo_id" as "__f__bar.foo_id", "bar"."created_at" as "__f__bar.created_at", "bar"."updated_at" as "__f__bar.updated_at", "bar"."baz_id" as "__f__bar.baz_id", "foo"."id" as "__f__bar.__f__foo.id", "foo"."title" as "__f__bar.__f__foo.title", "foo"."created_at" as "__f__bar.__f__foo.created_at", "foo"."updated_at" as "__f__bar.__f__foo.updated_at", "boms".* from "boms" left join "bars" as "bar" on "bar"."id" = "boms"."bar_id" left join "foos" as "foo" on "foo"."id" = "bar"."foo_id" where "foo"."id" = ? limit 1');
142+
$this->assertQuery('select "bar"."id" as "__f__bar---id", "bar"."title" as "__f__bar---title", "bar"."foo_id" as "__f__bar---foo_id", "bar"."created_at" as "__f__bar---created_at", "bar"."updated_at" as "__f__bar---updated_at", "bar"."baz_id" as "__f__bar---baz_id", "foo"."id" as "__f__bar---__f__foo---id", "foo"."title" as "__f__bar---__f__foo---title", "foo"."created_at" as "__f__bar---__f__foo---created_at", "foo"."updated_at" as "__f__bar---__f__foo---updated_at", "boms".* from "boms" left join "bars" as "bar" on "bar"."id" = "boms"."bar_id" left join "foos" as "foo" on "foo"."id" = "bar"."foo_id" where "foo"."id" = ? limit 1');
143143

144144
$this->assertQueryCount(1);
145145
}

tests/db/testing.sqlite

-6 KB
Binary file not shown.

0 commit comments

Comments
 (0)