Skip to content

Get relationship id from the resource#809

Merged
lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom
gottfrois:patch-1
Aug 31, 2016
Merged

Get relationship id from the resource#809
lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom
gottfrois:patch-1

Conversation

@gottfrois
Copy link
Copy Markdown
Contributor

We should avoid getting relationship id from the model directly to allow clients to customize how relationship ids are fetched. The resource exposes the relationship id through a method which delegates to the model. This way we allow clients to override the relationship id in the resource to fit their needs.

Today, by default, the resource object already delegate the relationship id method to the model:

class AuthorResource
end

class MessageResource
  has_one :author
end

message.author_id
=> 1
message._model.author_id
=> 1

This way, a client can override the relationship id method:

class MessageResource
  has_one :author

  def author_id
    @model.author.some_custom_id
  end
end

We should avoid getting relationship id from the `model` directly to allow clients to customize how relationship ids are fetched. The resource exposes the relationship id through a method which delegates to the `model`. This way we allow clients to override the relationship id in the resource to fit their needs.
@knapo
Copy link
Copy Markdown
Contributor

knapo commented Aug 23, 2016

+1

@lgebhardt lgebhardt merged commit a799ee0 into JSONAPI-Resources:master Aug 31, 2016
@lgebhardt
Copy link
Copy Markdown
Contributor

@gottfrois Thanks!

@gottfrois gottfrois deleted the patch-1 branch August 31, 2016 08:04
NuckChorris referenced this pull request in hummingbird-me/kitsu-server Dec 12, 2016
NuckChorris referenced this pull request in hummingbird-me/kitsu-server Dec 12, 2016
* Use jsonapi-resources beta

* Disable fields picking in feeds

* Disable eager_load_on_include on activity/activitygroup models

* Use ResourceSerializer directly

* Fix that

* Override cerebris/jsonapi-resources#809 behavior

* Override BaseResource#respond_to? to handle FK _id methods properly

* Oops

* Try and add caching to various models

* Stop caching ActivityGroups

* Cache Post, PostLike, Comment
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

Successfully merging this pull request may close these issues.

3 participants