Skip to content

Commit

Permalink
Fix pull request #368 by not defining primary_keys unless set.primary…
Browse files Browse the repository at this point in the history
…_keys is called.
  • Loading branch information
Charlie Savage committed May 21, 2017
1 parent b99417c commit bb6ee75
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/composite_primary_keys/base.rb
Expand Up @@ -7,20 +7,6 @@ class Base
NOT_IMPLEMENTED_YET = 'Not implemented for composite primary keys yet'

class << self
def primary_keys
unless defined?(@primary_keys)
reset_primary_keys
end
@primary_keys
end

# Don't like this method name, but its modeled after how AR does it
def reset_primary_keys
if self != base_class
self.primary_keys = base_class.primary_keys
end
end

alias_method :primary_key_without_composite_key_support=, :primary_key=
def primary_key=(keys)
unless keys.kind_of?(Array)
Expand Down Expand Up @@ -60,6 +46,20 @@ def composite?
end

module CompositeClassMethods
def primary_keys
unless defined?(@primary_keys)
reset_primary_keys
end
@primary_keys
end

# Don't like this method name, but its modeled after how AR does it
def reset_primary_keys
if self != base_class
self.primary_keys = base_class.primary_keys
end
end

def primary_key
primary_keys
end
Expand Down

0 comments on commit bb6ee75

Please sign in to comment.