Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Fixed belongs_to name in m:m join model to use the singularized relat…
Browse files Browse the repository at this point in the history
…ionship name

* This allows you to use a different relationship name from the target
  model.  Previously in this case it was assumed the relationship would
  always be the underscored target model name, which is not always true.

[#406 state:resolved]
  • Loading branch information
dkubb committed May 28, 2009
1 parent e968df2 commit b472863
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/dm-core/associations/many_to_many.rb
Expand Up @@ -36,8 +36,8 @@ def through
# can define the join model within their common namespace

DataMapper.repository(source_repository_name) do
many_to_one = join_model.belongs_to(join_relationship_name(target_model), :model => target_model)
one_to_many = source_model.has(min..max, join_relationship_name(join_model, true), :model => join_model)
many_to_one = join_model.belongs_to(name.to_s.singularize.to_sym, :model => target_model)
one_to_many = source_model.has(min..max, join_relationship_name(join_model), :model => join_model)

# initialize the child_key on the many to one relationship
# now that the source, join and target models are defined
Expand Down Expand Up @@ -188,10 +188,10 @@ def join_model_namespace_name

# TODO: document
# @api private
def join_relationship_name(model, plural = false)
def join_relationship_name(model)
namespace = join_model_namespace_name.first
relationship_name = Extlib::Inflection.underscore(model.base_model.name.sub(/\A#{namespace.name}::/, '')).gsub('/', '_')
(plural ? relationship_name.plural : relationship_name).to_sym
relationship_name.pluralize.to_sym
end

# TODO: document
Expand Down

0 comments on commit b472863

Please sign in to comment.