diff --git a/src/Translatable.php b/src/Translatable.php index 016ae42..a757b2c 100644 --- a/src/Translatable.php +++ b/src/Translatable.php @@ -299,6 +299,10 @@ public function translationModel() */ public function translatableAttributes() { + if(!isset(static::$i18nAttributes[$this->getTable()])) { + return []; + } + return static::$i18nAttributes[$this->getTable()]; } diff --git a/src/TranslatableScope.php b/src/TranslatableScope.php index 9c7cab4..59a9a07 100644 --- a/src/TranslatableScope.php +++ b/src/TranslatableScope.php @@ -34,9 +34,11 @@ public function apply(EloquentBuilder $builder, Eloquent $model) $this->i18nTable = $model->getI18nTable(); $this->fallback = $model->getFallbackLocale(); - $this->createJoin($builder, $model); - $this->createWhere($builder, $model); - $this->createSelect($builder, $model); + if(!starts_with($this->table, 'laravel_reserved_')) { + $this->createJoin($builder, $model); + $this->createWhere($builder, $model); + $this->createSelect($builder, $model); + } } /** diff --git a/tests/IntegrationTestCase.php b/tests/IntegrationTestCase.php index 3f95ee4..edb64b2 100644 --- a/tests/IntegrationTestCase.php +++ b/tests/IntegrationTestCase.php @@ -39,6 +39,7 @@ public function setUp() $this->schema()->create('tags', function (Blueprint $table) { $table->increments('id'); + $table->integer('parent_id')->unsigned()->nullable(); $table->timestamps(); }); diff --git a/tests/TestCRUD.php b/tests/TestCRUD.php index f110ad0..29233cd 100644 --- a/tests/TestCRUD.php +++ b/tests/TestCRUD.php @@ -300,4 +300,16 @@ public function testIncrementDecrement() $user->decrement('age'); $this->assertEquals(20, User::first()->age); } + + public function testHasQuery() + { + $tag1 = Tag::forceCreate(['title' => 'Tag1']); + $tag2 = Tag::forceCreate(['title' => 'Tag2']); + $tag3 = Tag::forceCreate(['title' => 'Tag2']); + + $tag3->parent_id = $tag1->id; + $tag3->save(); + + $this->assertCount(1, Tag::has('children')->get()); + } } diff --git a/tests/stubs/Tag.php b/tests/stubs/Tag.php index 11c12f3..ac91934 100644 --- a/tests/stubs/Tag.php +++ b/tests/stubs/Tag.php @@ -13,4 +13,9 @@ public function posts() { return $this->belongsToMany(Post::class); } + + public function children() + { + return $this->hasMany(static::class, 'parent_id', 'id'); + } } \ No newline at end of file