Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Respect :unique_index option in #belongs_to
Browse files Browse the repository at this point in the history
This simply passes the :unique_index passed to
#belongs_to on to ManyToOne#source_key_options

I have no time for refamiliarizing myself with the
testsuite, but it works for our app.
  • Loading branch information
snusnu committed Mar 22, 2014
1 parent 7cc4c14 commit a74f9ec
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/dm-core/associations/many_to_one.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def initialize(name, source_model, target_model, options = {})
@required = options.fetch(:required, true)
@key = options.fetch(:key, false)
@unique = options.fetch(:unique, false)
@unique_index = options.fetch(:unique_index, false)
target_model ||= DataMapper::Inflector.camelize(name)
options = { :min => @required ? 1 : 0, :max => 1 }.update(options)
super
Expand Down Expand Up @@ -260,10 +261,11 @@ def inverse_name
# @api private
def source_key_options(target_property)
options = DataMapper::Ext::Hash.only(target_property.options, :length, :precision, :scale).update(
:index => name,
:required => required?,
:key => key?,
:unique => @unique
:index => name,
:required => required?,
:key => key?,
:unique => @unique,
:unique_index => @unique_index
)

if target_property.primitive == Integer
Expand Down

0 comments on commit a74f9ec

Please sign in to comment.