Skip to content

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

Closed
@blakemcintyre

Description

@blakemcintyre

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions