Skip to content

Commit

Permalink
Improve Rails 5.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jkowens committed May 23, 2017
1 parent bb40a9e commit 635938d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Associations
class Preloader
class Association
silence_warnings do
def query_scope(ids)
def records_for(ids)
# CPK
# scope.where(association_key.in(ids))
# scope.where(association_key_name => ids)

if reflection.foreign_key.is_a?(Array)
predicate = cpk_in_predicate(table, reflection.foreign_key, ids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module ActiveRecord
module Associations
class Preloader
class BelongsTo
def query_scope(ids)
def records_for(ids)
# CPK
# scope.where(association_key.in(ids))

if association_key_name.is_a?(Array)
predicate = cpk_in_predicate(table, association_key_name, ids)
scope.where(predicate)
else
scope.where(association_key.in(ids))
scope.where(association_key_name => ids)
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions lib/composite_primary_keys/attribute_methods/write.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ module ActiveRecord
module AttributeMethods
module Write
silence_warnings do
def write_attribute(attr_name, value)
name = if self.class.attribute_alias?(attr_name)
# CPK
# self.class.attribute_alias(attr_name).to_s
self.class.attribute_alias(attr_name)
else
# CPK
# attr_name.to_s
attr_name
end

write_attribute_with_type_cast(name, value, true)
end

def write_attribute_with_type_cast(attr_name, value, should_type_cast)
# CPK
if attr_name.kind_of?(Array)
Expand Down

0 comments on commit 635938d

Please sign in to comment.