-
Notifications
You must be signed in to change notification settings - Fork 43
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
Unexpected plural when making relationships #63
Comments
You will have de declare the type Smth like that ` BelongsToMany::make('users')->type('user') ` |
Thanks, that worked, but why is this needed? With this code I connect a field name ( |
It's because the default behaviour of the package is to assume that resource types are pluralized. Hmmm, yeah I suppose for Eloquent relations you could lookup the inverse schema to get the type. My only hesitancy with doing that is it adds a load of extra processing (imagine every schema had to look it up for every relationship, that's potentially a lot of relationships). One other thing is that the relationship fields are not currently injected with the schema they belong to. That would have to happen so they can get the model class, to then lookup the relation, to then get the model from the relation, to then resolve the correct schema using that related model, to then get the schema type. That again would need to happen for every single relation. |
Okay. |
I made a schema for my model
Token
with the following fields:However, when I request the endpoint, I get an 500 error. When I look at the logs:
In the error, the resource type is suddenly plural. Why does this happen? (It also happens with
user
.)Note, for my class
Token
, the following constants exist (and as you see, they are all different):Token::class
The full name of the classToken::TYPE
The type of the resource; in this caseauth_token
; will be in the JSON type field:type="auth_token"
Token::URI
The uri of the resource; in this casetokens
; will be in the URL of my API:/v1/tokens/1?page[number]=2
Token::PARAM
The param of the resource; in this casetoken
; will be the name of the parameter:/v1/tokens/{token}
The text was updated successfully, but these errors were encountered: