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

Side loading doesn't work in 0.10.0.rc1 (non-JSONAPI) #899

Closed
blakemcintyre opened this issue May 4, 2015 · 14 comments
Closed

Side loading doesn't work in 0.10.0.rc1 (non-JSONAPI) #899

blakemcintyre opened this issue May 4, 2015 · 14 comments
Assignees
Milestone

Comments

@blakemcintyre
Copy link

I've been trying to setup side loading using the standard adapter, (not JSONAPI), and have been unable to generate any embedded data. This works in 0.8.1 but the issue stated in #377 has lead me to trying 0.10.x. When I tried using the JSONAPI adapter I was able to get included/linked data.

The following is the basic setup I've been testing with:

class ArticleSerializer < ActiveModel::Serializer
  attributes :id, :title, :published_at

  has_many :authors, embed: :ids, serializer: UserSerializer

  url :article
end

class UserSerializer < ActiveModel::Serializer
  attributes :id, :name

  url :user
end


class Article < ActiveRecord::Base
  has_many :article_authors
  has_many :authors, through: :article_authors, class: User
end

class ArticleAuthor < ActiveRecord::Base
  belongs_to :article
  belongs_to :author, class: User
end

class User < ActiveRecord::Base
  has_many :article_authors, foreign_key: :author_id
  has_many :articles, through: :article_authors
end


class ArticlesController < ApplicationController
  def index
    render json: Article.last(3), root: :articles, include: 'authors'
  end
end
@henrymazza
Copy link

+1

I’m using ember-data, is there a way to achieve the same format I had with 0.8.x? That is with embed :ids and associations sideloaded?

@meltingice
Copy link

This is currently the only thing stopping me from upgrading to 0.10.x. In order to maintain the same API format and prevent breaking our client, I need to be able to sideload objects in the root.

@joaomdmoura joaomdmoura added this to the 0.10 milestone May 8, 2015
@joaomdmoura joaomdmoura self-assigned this May 8, 2015
@henrymazza
Copy link

Now I hear that ember data is aiming to the same JSONAPI format that AMS 0.10.x is defaulting to. Plus it should ship a compatible beta version somewhere in June.

Can someone confirm this?

Enviado de um aparelho móvel.

On 08/05/2015, at 10:37, Ryan LeFevre [email protected] wrote:

This is currently the only thing stopping me from upgrading to 0.10.x. In order to maintain the same API format and prevent breaking our client, I need to be able to sideload objects in the root.


Reply to this email directly or view it on GitHub.

@meltingice
Copy link

For what it's worth, we aren't using the JSONAPI spec, but we still need to sideload data. I've been playing around with the JSON adapter in order to add the functionality back. I'll see if I can get a proof-of-concept together.

@joaomdmoura
Copy link
Member

Hey everybody, I'm just jumping in to let you know that I'm following this and will try to give it a closer look on the weekend. @meltingice would be awesome to have some prof-of-concept 😄
Thank y'all! ❤️

@benwoodward
Copy link

+1

@saneshark
Copy link

I've been using a decorator pattern, decorating the collection with an instance variable that has my sideloaded query set and group_by(:foreign_key_id), then my individual decorator overrides the association method, doing a hash lookup based on the sideloaded hash or super if the hash was not passed in as part of the collection's context. For me this is necessary no matter what since my API consumer needs to pass in parameters limiting the scope of the association as well (has_many).

@jtippett
Copy link

jtippett commented Jun 9, 2015

+1

@joaomdmoura
Copy link
Member

@henrymazza confirmed. Ember, as far as I know, is moving forward to use JSON-API. We had to remove it as default because of a WIP Rails integration, but it's already supported and extremely easy to use.

@ahmeij
Copy link
Contributor

ahmeij commented Aug 26, 2015

We are not using ember, however we are using 0.9 with embed: ids, and sideloading. this works quite well for us however since we desperately need caching we'd like to upgrade to 0.10.

As we have multiple clients for our api based on the above model updating the output to be compatible with json_api is a ways off.

Is there a way to upgrade? // did someone make a json_legacy adapter maybe? I think this is definitely needed to avoid breaking all api's out there when upgrading to 0.10

I will take a stab at making a legacy adapter if none exists

@NullVoxPopuli
Copy link
Contributor

I have a pull request #1088 which I hope addresses this for most people

@joaomdmoura
Copy link
Member

Nice to see this being bumped! I'll check both PRs @ahmeij && @NullVoxPopuli

@remear
Copy link
Member

remear commented Mar 15, 2016

Looks like #1088 + #1111 + #1114 resolved this

@remear remear closed this as completed Mar 15, 2016
@bf4
Copy link
Member

bf4 commented Jun 1, 2016

Also see #1127

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

No branches or pull requests