nilportugues / php-api-transformer

Base library providing the core functionality for API transformation.
http://nilportugues.com
MIT License
9 stars 10 forks source link

Defining relationships seems to be broken #10

Open therealcljohn opened 8 years ago

therealcljohn commented 8 years ago

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 commented 8 years ago

@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: