576/5000
I have 4 models, Resellers, Address, Products, Categories
I need to list all Resellers together with the addresses and products, however they are Resellers that contain products of category X (if the params came with category in the request)
But every time I try to do something, it goes wrong.
I tried to use preload but I can’t limit the quantity of products in the category, so there are more than 100 products for each Reseller.
I really need help, I tried several times and was unsuccessful, I don’t know if I modeled the best way but I’m trying to learn.
schema “resellers” do
field :description, :string
field :email, :string
field :encrypted_password, :string
field :name, :string
field :tax_code, :string
field :phone, :string
field :store_name, :string
# VIRTUAL FIELDS
field :password, :string, virtual: true
field :password_confirmation, :string, virtual: true
has_one :address, Address
has_many :products, Product
timestamps()
end
schema “addresses” do
field :complement, :string
field :country, :string
field :number, :string
field :observation, :string
field :state, :string
field :street, :string
field :zip_code, :string
field :lat, :float
field :long, :float
belongs_to :reseller, Reseller
timestamps()
end
schema “products” do
field :description, :string
field :name, :string
field :price, :decimal
field :brand, :string
field :quantity, :decimal
field :size, :string
field :category_id, :integer
field :deleted_at, :utc_datetime
field :is_active, :boolean
field :cost, :decimal
belongs_to :reseller, Reseller
has_many :product_images, ProductImage
timestamps()
end
schema “categories” do
field :name, :string
timestamps()
end