Skip to content

Commit

Permalink
Fixed Model.associate to accept class and class name in :class option.
Browse files Browse the repository at this point in the history
  • Loading branch information
noteflakes committed Mar 9, 2008
1 parent da6ec33 commit 46c139b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
4 changes: 4 additions & 0 deletions sequel_model/CHANGELOG
@@ -1,3 +1,7 @@
=== SVN

* Fixed Model.associate to accept class and class name in :class option.

=== 0.5 (2008-03-08)

* Merged new associations branch into trunk.
Expand Down
7 changes: 2 additions & 5 deletions sequel_model/lib/sequel_model/associations.rb
Expand Up @@ -80,12 +80,9 @@ def all_association_reflections
#
# The following options can be supplied:
# * *ALL types*:
# - :class_name - The name of the associated class as a string. If not
# - :class - The associated class or its name. If not
# given, uses the association's name, which is camelized (and
# singularized if type is :{one,many}_to_many)
# - :class - The associated class itself. Simpler than using
# :class_name, but can't be used always due to dependencies not being
# loaded.
# * :many_to_one:
# - :key - foreign_key in current model's table that references
# associated model's primary key, as a symbol. Defaults to :"#{name}_id".
Expand Down Expand Up @@ -117,7 +114,7 @@ def associate(type, name, opts = {}, &block)
end

# prepare options
opts[:class_name] ||= opts[:class].name if opts[:class]
opts[:class_name] ||= opts[:class].to_s if opts[:class]
opts = association_reflections[name] = opts.merge(:type => type, :name => name, :block => block)

send(:"def_#{type}", name, opts)
Expand Down
30 changes: 12 additions & 18 deletions sequel_model/spec/associations_spec.rb
Expand Up @@ -150,9 +150,8 @@ def columns; [:id, :node_id]; end
@c2 = Class.new(Sequel::Model(:nodes)) do
attr_accessor :xxx

def self.name
'Node'
end
def self.name; 'Node'; end
def self.to_s; 'Node'; end
end
@dataset = @c2.dataset

Expand Down Expand Up @@ -353,17 +352,15 @@ class HistoricalValue < Sequel::Model
MODEL_DB.reset

@c1 = Class.new(Sequel::Model(:attributes)) do
def self.name
'Attribute'
end
def self.name; 'Attribute'; end
def self.to_s; 'Attribute'; end
end

@c2 = Class.new(Sequel::Model(:nodes)) do
attr_accessor :xxx

def self.name
'Node'
end
def self.name; 'Node'; end
def self.to_s; 'Node'; end
end
@dataset = @c2.dataset

Expand Down Expand Up @@ -546,9 +543,8 @@ class Tag < Sequel::Model
before(:each) do
MODEL_DB.reset
@c1 = Class.new(Sequel::Model(:nodes)) do
def self.name
'Node'
end
def self.name; 'Node'; end
def self.to_s; 'Node'; end
end
end

Expand All @@ -572,9 +568,8 @@ def self.name
before(:each) do
MODEL_DB.reset
@c1 = Class.new(Sequel::Model(:nodes)) do
def self.name
'Node'
end
def self.name; 'Node'; end
def self.to_s; 'Node'; end
end
end

Expand All @@ -600,9 +595,8 @@ def self.name
before(:each) do
MODEL_DB.reset
@c1 = Class.new(Sequel::Model(:nodes)) do
def self.name
'Node'
end
def self.name; 'Node'; end
def self.to_s; 'Node'; end
end
end

Expand Down

0 comments on commit 46c139b

Please sign in to comment.