Problem when including "morphTo" and "belongsTo" relations when using "allowedFields"? #554
Answered
by
n-u-l-l-e-d
n-u-l-l-e-d
asked this question in
Q&A
-
Would it be a bug, an unsupported option, or perhaps it should be done differently? I use version 8.11.2 of Laravel. ❌ /** @test */
public function it_can_include_morph_to_relation_when_using_allowed_fields()
{
$request = new Request([
'include' => 'parent',
'fields' => [
'morph_models' => 'id'
],
]);
$model = QueryBuilder::for(MorphModel::class, $request)
->allowedFields('id')
->allowedIncludes('parent')
->first()
->toArray();
$this->assertNotNull($model['parent']);
} ❌ /** @test */
public function it_can_include_belongs_to_relation_when_using_allowed_fields()
{
$request = new Request([
'include' => 'test-model',
'fields' => [
'related_models' => 'id'
],
]);
$model = QueryBuilder::for(RelatedModel::class, $request)
->allowedFields('id')
->allowedIncludes('test-model')
->first()
->toArray();
$this->assertNotNull($model['test_model']);
} ✔️ /** @test */
public function it_can_include_morph_to_relation_when_not_using_allowed_fields()
{
$request = new Request([
'include' => 'parent',
]);
$model = QueryBuilder::for(MorphModel::class, $request)
->allowedIncludes('parent')
->first()
->toArray();
$this->assertNotNull($model['parent']);
} ✔️ /** @test */
public function it_can_include_belongs_to_relation_when_not_using_allowed_fields()
{
$request = new Request([
'include' => 'test-model',
]);
$model = QueryBuilder::for(RelatedModel::class, $request)
->allowedIncludes('test-model')
->first()->toArray();
$this->assertNotNull($model['test_model']);
} ✔️ /** @test */
public function it_can_include_has_many_relations_when_using_allowed_fields()
{
$request = new Request([
'include' => 'other-related-models',
'fields' => [
'test_models' => 'id'
],
]);
$model = QueryBuilder::for(TestModel::class, $request)
->allowedFields('id')
->allowedIncludes('other-related-models')
->first()
->toArray();
$this->assertNotNull($model['other_related_models']);
} Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
n-u-l-l-e-d
Oct 24, 2020
Replies: 2 comments
-
An issue has been created for this topic. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
n-u-l-l-e-d
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solved!