Sha256: c7fdf046cae703a02777d3a70386ff4eca6a050e317245f29e7c3e0cd9f589eb

Contents?: true

Size: 1.11 KB

Versions: 7

Compression:

Stored size: 1.11 KB

Contents

require 'active_record'

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
    t.string :title
    t.text :body
    t.references :author
    t.timestamps null: false
  end
  create_table :authors, force: true do |t|
    t.string :name
    t.timestamps null: false
  end
  create_table :comments, force: true do |t|
    t.text :contents
    t.references :author
    t.references :post
    t.timestamp null: false
  end
end

module ARModels
  class Post < ActiveRecord::Base
    has_many :comments
    belongs_to :author
  end

  class Comment < ActiveRecord::Base
    belongs_to :post
    belongs_to :author
  end

  class Author < ActiveRecord::Base
    has_many :posts
  end

  class PostSerializer < ActiveModel::Serializer
    attributes :id, :title, :body

    has_many :comments
    belongs_to :author
  end

  class CommentSerializer < ActiveModel::Serializer
    attributes :id, :contents

    belongs_to :author
  end

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

    has_many :posts
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
active_model_serializers-0.10.0.rc4 test/fixtures/active_record.rb
active_model_serializers-0.10.0.rc3 test/fixtures/active_record.rb
cheap_ams-0.10.11 test/fixtures/active_record.rb
cheap_ams-0.10.10 test/fixtures/active_record.rb
cheap_ams-0.10.8 test/fixtures/active_record.rb
cheap_ams-0.10.7 test/fixtures/active_record.rb
cheap_ams-0.10.6 test/fixtures/active_record.rb