Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including an Invalid Relation Shouldn't Throw Exception #73

Closed
brunogaspar opened this issue Oct 22, 2017 · 5 comments
Closed

Including an Invalid Relation Shouldn't Throw Exception #73

brunogaspar opened this issue Oct 22, 2017 · 5 comments

Comments

@brunogaspar
Copy link
Contributor

brunogaspar commented Oct 22, 2017

Hi

First, thanks for the package, it has been really helpful :)

Now for the issue.

If i have defined a list of available relations on the transformer and then when i do a request and i request to include a relation that's not on that list and at the same time is invalid (doesn't exist on the model), it throws an exception about the relation being invalid, IMO, that shouldn't throw the exception, at all, since that's not on the list of the available relations.

Transformer:

<?php

namespace App\Transformers;

use App\Models\Client;

class ClientTransformer extends Transformer
{
    /**
     * List of available relations.
     *
     * @var array
     */
    protected $relations = ['invoices'];

    // Truncated for brevity
}

If i hit http://foo.dev/clients?with=invalid_relation an exception is thrown.

And if for example, i make that array empty and require ?with=invoices it doesn't throw an error, which is kinda expected, since it's not allowed.

I know i can catch the exception and deal with it, however, i don't feel that this is the correct behaviour.

Thanks!

@flugg
Copy link
Owner

flugg commented Oct 23, 2017

Hi @brunogaspar, I agree with your sentiment! I'll look into it soon, hopefully tonight. Thanks!

@brunogaspar
Copy link
Contributor Author

Thank you @Flugger !

@flugg
Copy link
Owner

flugg commented Oct 25, 2017

Sorry for the delay, been a hectic week at work. I'll try to look at this over the weekend

@brunogaspar
Copy link
Contributor Author

No worries, take your time.

Thanks!

@flugg
Copy link
Owner

flugg commented Jan 28, 2018

I feel bad about this taking so long, but at least this should be fixed with the latest v3.0.0 release! Let me know if you still have problems

@flugg flugg closed this as completed Jan 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants