Hi,
According to the associations documentation
(http://sequel.rubyforge.org/rdoc/files/doc/association_basics_rdoc.html) :
----
"If you nest your Sequel::Model classes inside modules, then you should
know that Sequel will only look in the same module for associations by
default. So the following code will work fine:"
module App
class Artist < Sequel::Model
one_to_many :albums
end
class Album < Sequel::Model
many_to_one :artist
end
end
However, if you enclose your model classes inside two different modules,
things will not work by default:
module App1
class Artist < Sequel::Model
one_to_many :albums
end
end
module App2
class Album < Sequel::Model
many_to_one :artist
end
end
To fix this, you need to specify the full model class name using the :class
option:
module App1
class Artist < Sequel::Model
one_to_many :albums, :class=>"App2::Album"
end
end
module App2
class Album < Sequel::Model
many_to_one :artist, :class=>"App1::Artist"
end
end
----
However, what I observe with Sequel 3.26 is that when I have all my models
in a single file and in a single module (e.g., SomeModule) _and_ some
association need to reference another model in the same module (in the same
file) by using the :class parameter I _must_ name the associated model not
using the symbol format but the string format. Otherwise I get the
inflector 'constantize' NameError:
"sequel-3.26.0/lib/sequel/model/inflections.rb:125:in `constantize':
uninitialized constant MyModel (NameError)"
e.g., to make it work I need to do:
one_to_many :some_funny_name_models , :class => "SomeModule::MyModel"
as opposed to:
one_to_many :some_funny_name_models , :class => :MyModel
Is this a) a problem with the documentation, b) a bug in my version of
Sequel or perhaps I'm totally wrong in my understanding?
cheers
/pagojo
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/ThZQaC9LKzMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.