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

How to add default values to POST, query by a scope #101

Open
marceloandrader opened this issue Sep 28, 2016 · 1 comment
Open

How to add default values to POST, query by a scope #101

marceloandrader opened this issue Sep 28, 2016 · 1 comment

Comments

@marceloandrader
Copy link

Hey, thanks for this library I'm just starting to use it and looks really promising.

One thing that my app has is that is multi-tenant, so most of the api endpoints will return data with a specific scope, in a normal index controller I can do Entity::forOrg(Auth::user()->organization_id) returning only the Entity for the org of the user. What is the best way to do that on the JsonApiController subclasses?

And also when creating this kind of records, I need to set that organization_id column to the value of the user->organization_id, thanks in advance.

@marceloandrader
Copy link
Author

I was able to fix the scope issue using global scopes.

But the other thing I tried setting the organization_id on the Entity::creating event, but that is never fired, looks like the DataObject expects all fields on the attributes key and get an error about 2 fields, one is the org_id that is not sent and the other is a relationship field.

I'm using Ember data to try to make a POST, so the POST looks like:

post

And the response is:

response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant