9595 t . integer :mentor_id
9696 t . integer :mentee_id
9797 end
98+
99+ create_table :sales_shops do |t |
100+ t . string :name
101+ end
102+
103+ create_table :sales_stocks do |t |
104+ t . integer :book_id
105+ t . integer :shop_id
106+ t . integer :amount
107+ end
98108end
99109
100110module Legacy
@@ -186,6 +196,8 @@ class Book < ApplicationRecord
186196 has_many :tags , through : :taggings
187197 has_many :readerships
188198 has_many :readers , through : :readerships , source : :user
199+ has_many :sales_stocks , class_name : "Legacy::Sales::Stock"
200+ has_many :sales_shops , class_name : "Legacy::Sales::Shop" , through : :sales_stocks , source : :shop
189201 end
190202
191203 class User < ApplicationRecord
@@ -208,6 +220,22 @@ class Tagging < ApplicationRecord
208220 belongs_to :tag
209221 end
210222
223+ module Sales
224+ def self . table_name_prefix
225+ "sales_"
226+ end
227+
228+ class Stock < ApplicationRecord
229+ belongs_to :book
230+ belongs_to :shop
231+ end
232+
233+ class Shop < ApplicationRecord
234+ has_many :stocks
235+ has_many :books , through : :stocks , inverse_of : :sales_shops
236+ end
237+ end
238+
211239 class LegacyApplicationSerializer < Graphiti ::Serializer
212240 end
213241
@@ -245,6 +273,20 @@ class BookResource < ApplicationResource
245273 many_to_many :readers , resource : Legacy ::UserResource
246274 end
247275
276+ module Sales
277+ class StockResource < ApplicationResource
278+ attribute :amount , :integer
279+ belongs_to :book
280+ belongs_to :shop
281+ end
282+
283+ class ShopResource < ApplicationResource
284+ attribute :name , :string
285+ has_many :stocks
286+ many_to_many :books , resource : Legacy ::BookResource , foreign_key : { sales_stocks : :shop_id }
287+ end
288+ end
289+
248290 class StateResource < ApplicationResource
249291 attribute :name , :string
250292 attribute :abbreviation , :string do
0 commit comments