1

How can I add the Mongoid associations for fast_jsonapi?

embeds_many
embeds_one

I'm trying to upgrade from my rabl serialization to fast_jsonapi. Is this even possible?

Mongoid 5.4 fast_jsonapi 1.5

jmoon90
  • 339
  • 4
  • 17

2 Answers2

0

fast_jsonapi is implemented on visitor design pattern. so underline data structure is nothing to consider, just use has_many and has_one accordingly. anyway, if you check GitHub issues list you can see that is has tested on latest mongoid versions.

Oshan Wisumperuma
  • 1,808
  • 1
  • 18
  • 32
0

I've followed this guide from #[soundstripe][1]

[1]: https://medium.com/soundstripe-engineering/greener-pastures-migrating-a-production-api-from-activemodel-serializers-to-fast-json-api-9627be51c64 to figure out how to get fast-jsonapi to work for me. But in general it looks like you just need these pieces of the code to make it work.

class BookSerializer < ApplicationSerializer
  belongs_to :library
end

class BooksController < ApplicationController
  def index
    @books = Book.all
    render jsonapi: BookSerializer.new(@books)
  end
end

class ApplicationSerializer
  include FastJsonapi::ObjectSerializer
end
jmoon90
  • 339
  • 4
  • 17