I am working on a module that interacts with components of an existing database with tables: `Brand`, `Model`, `Submodel` and came across an issue while defining an association.
Generally speaking, my models look like this: module COC class Brand < Sequel::Model one_to_many :models end class Model < Sequel::Model many_to_one :brand one_to_many :submodels end class Submodel < Sequel::Model many_to_one :model end end I was hesitant to use the class name `Model`, but largely it has been working as expected. My issues came about when trying to create instances of `Submodel`, and it seems to be caused by the association setup: many_to_one :model With that line, I am unable to create new instances of the model that are sensible, and I suspect it's tied to the usage of trying to associate `:model`. If it's commented out, the model works as expected. Is there an alternate way to specify the `one_to_many` call that will allow me to target my `Model` class? Or must I rename the class? Here's some code that led me to this: [112] pry(main)> model.add_submodel attributes NoMethodError: undefined method `setter_methods' for nil:NilClass from /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/base.rb:2494:in `setter_methods' [113] pry(main)> wtf? Exception: NoMethodError: undefined method `setter_methods' for nil:NilClass -- 0: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/ base.rb:2494:in `setter_methods' 1: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/base.rb:2463:in `set_restricted' 2: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/base.rb:1852:in `set' 3: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/ base.rb:2421:in `initialize_set' 4: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/base.rb:1440:in `initialize' 5: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/associations.rb:2480:in `new' 6: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/ associations.rb:2480:in `make_add_associated_object' 7: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/associations.rb:2352:in `add_associated_object' 8: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/associations.rb:1942:in `block in def_association_instance_methods' [16] pry(main)> COC::Submodel.new params NoMethodError: undefined method `setter_methods' for nil:NilClass from /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/base.rb:2494:in `setter_methods' [22] pry(main)> submodel = COC::Submodel.new [23] pry(main)> submodel.set params NoMethodError: undefined method `setter_methods' for nil:NilClass from /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/base.rb:2494:in `setter_methods' [24] pry(main)> wtf??? Exception: NoMethodError: undefined method `setter_methods' for nil:NilClass -- 0: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/ base.rb:2494:in `setter_methods' 1: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/base.rb:2463:in `set_restricted' 2: /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/base.rb:1852:in `set' [31] pry(main)> submodel.url = 'tim' NoMethodError: undefined method `db' for nil:NilClass from /home/ttilberg/.rvm/gems/ruby-2.2.5/gems/sequel-4.49.0/lib/sequel/model/base.rb:2527:in `typecast_value' This object looks different than a normal new `Sequel::Model` -- it's missing @values. [5] pry(main)> COC::Submodel.new => #<COC::Submodel:0x1fb02ec> With the association line commented out, the class initializes with `@values` and works as usual. [9] pry(main)> COC::Submodel.new => #<COC::Submodel @values={}> I fear the answer to this question will simply be "Don't use the class name `Model`" -- I'd like to avoid this, as the word Model is the most meaningful in our context, and is largely established in the greater system. Thank you for reading! -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.