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

Defining relationships seems to be broken #10

Open
therealcljohn opened this issue Jun 30, 2016 · 1 comment
Open

Defining relationships seems to be broken #10

therealcljohn opened this issue Jun 30, 2016 · 1 comment

Comments

@therealcljohn
Copy link

I'm trying to unterstand how relationships in the jsonapi library work and defined a relationship in my transformer:

    public function getRelationships()
    {
      return [
          'roles' => [
              'self' => 'http://example.com/user/{userId}/roles',
          ]
      ];
    }

But this throws me the following error: Could not find property roles in class App\\Models\\User because it does not exist.. But it definetly does exist (note: laravel uses dynamic properties for relations and I can call $model->roles manually).

I tracked this down to MappingFactory::getClassProperties() where you determine all properties of the used model by using the ReflectionClass. The problem is, that this method does only return all properties that represent columns in the database but it does not return the dynamic properties that laravel uses for relations.

I cannot digg this any further because this gets much deeper than my knowlegde. I'm especially interested in CREATE and DELETE of relations like described here http://jsonapi.org/format/#crud-updating-relationships and would be interested if this is possible with the jsonapi package.

Maybe you can give me a short feedback on how to use relations or if CREATE and DELETE on relations is supported or a hint on how to fix this issue. That would be great.

@nilportugues
Copy link
Owner

nilportugues commented Jun 30, 2016

@floh1111 I really need to document this more, as I have tested this already but maybe not all cases.

I believe additional code must be placed in here:

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

2 participants