has_many relations in Ruby on Rails 5.0 -


i have been struggling time problem in rails app. have 3 classes, merchandise, merchandisecategory , merchandisemerchandisecategory. merchandisemerchandisecategory used create many-to-many relation between other two.

when run following commands in rails console, corresponding results:

m = merchandisemerchandisecategory.first # returns object relates first merchandise # first merchandise category  m.merchandise_category # returns corresponding merchandise_category  m.merchandise_category.merchandise_merchandise_categories.first # returns array of corresponding merchandisemerchandisecategy ids  m.merchandise # returns corresponding merchandise  m.merchandise.merchandise_merchandise_categories.first # loaderror: unable autoload constant # merchandise::merchandisemerchandisecategory, expected # /home/bjarki/development/h2/app/models/merchandise/merchandise_merchandise_category.rb # define 

so, relations work except one-to-many relation between merchandise , merchandisemerchandisecategory. have tried think of, including deleting merchandise model , recreating it.

these classes i'm working with

merchandise.rb

# branch_id: uuid # name: string # price: integer class merchandise < applicationrecord   has_many :merchandise_merchandise_categories   has_many :categories, class_name: :merchandisecategory,                         through: :merchandise_merchandise_categories   belongs_to :branch end 

merchandise_category.rb

# branch_id: uuid # name : string class merchandisecategory < applicationrecord   has_many :merchandise_merchandise_categories   has_many :merchandises, through: :merchandise_merchandise_categories   belongs_to :branch end 

merchandise_merchandise_category.rb

# merchandise_id: uuid # merchandise_category_id: uuid class merchandisemerchandisecategory < applicationrecord   belongs_to :merchandise   belongs_to :merchandise_category end 

this has been driving me crazy last days. grateful if point me towards right direction.

put

merchandise_merchandise_category.rb in

app/models/merchandise/merchandise_merchandise_category.rb

let me know


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -