Skip to content

Commit

Permalink
Merge branch 'master' of github.com:composite-primary-keys/composite_…
Browse files Browse the repository at this point in the history
…primary_keys
  • Loading branch information
Charlie Savage committed May 21, 2017
2 parents 0627b44 + cac0560 commit a7460b2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
17 changes: 17 additions & 0 deletions lib/composite_primary_keys/associations/collection_association.rb
Expand Up @@ -6,6 +6,23 @@ def get_records
super
end

def ids_reader
if loaded?
load_target.map do |record|
if reflection.association_primary_key.is_a?(Array)
reflection.association_primary_key.map { |key| record.send(key) }
else
record.send(reflection.association_primary_key)
end
end
else
@association_ids ||= (
column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}"
scope.pluck(column)
)
end
end

def ids_writer(ids)
pk_type = reflection.primary_key_type
ids = Array(ids).reject(&:blank?)
Expand Down
2 changes: 1 addition & 1 deletion tasks/databases/oracle.rake
Expand Up @@ -14,7 +14,7 @@ namespace :oracle do
sql = File.read(schema)

sql.split(';').each do |command|
ActiveRecord::Base.connection.execute(command)
ActiveRecord::Base.connection.execute(command) unless command.blank?
end

ActiveRecord::Base.clear_all_connections!
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/db_definitions/mysql.sql
Expand Up @@ -39,8 +39,8 @@ create table tariffs (
tariff_id int not null,
start_date date not null,
amount integer(11) default null,
created_at timestamp,
updated_at timestamp,
created_at datetime,
updated_at datetime,
primary key (tariff_id, start_date)
);

Expand Down
2 changes: 1 addition & 1 deletion test/test_preload.rb
@@ -1,7 +1,7 @@
require File.expand_path('../abstract_unit', __FILE__)

class TestPreload < ActiveSupport::TestCase
fixtures :comments, :users, :employees, :groups
fixtures :comments, :users, :employees, :groups, :hacks

class UserForPreload < User
has_many :comments_with_include_condition, -> { where('person_type = ?', 'User')},
Expand Down

0 comments on commit a7460b2

Please sign in to comment.