Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/lib/composite_primary_keys/relation/batches.rb b/lib/composite_primary_keys/relation/batches.rb
- index 8a93960..38b6c9c 100644
- --- a/lib/composite_primary_keys/relation/batches.rb
- +++ b/lib/composite_primary_keys/relation/batches.rb
- @@ -23,7 +23,13 @@ module CompositePrimaryKeys
- # CPK
- #records = relation.where(table[primary_key].gteq(start)).all
- self.primary_key.each do |key|
- - relation = relation.where(table[key].gteq(start))
- + condition = case relation.columns_hash[key.to_s].type
- + when :string
- + table[key].not_eq ''
- + when :integer
- + table[key].gteq start
- + end
- + relation = relation.where(condition)
- end
- records = relation.all
- diff --git a/test/fixtures/db_definitions/postgresql.sql b/test/fixtures/db_definitions/postgresql.sql
- index 1990124..6e507a3 100644
- --- a/test/fixtures/db_definitions/postgresql.sql
- +++ b/test/fixtures/db_definitions/postgresql.sql
- @@ -192,3 +192,11 @@ create table employees_groups (
- employee_id int not null,
- group_id int not null
- );
- +
- +create table titles (
- + entity character varying(255),
- + entity_id integer,
- + lang_id integer,
- + title text,
- + primary key (entity, entity_id, lang_id)
- +);
- \ No newline at end of file
- diff --git a/test/fixtures/title.rb b/test/fixtures/title.rb
- new file mode 100644
- index 0000000..a11b726
- --- /dev/null
- +++ b/test/fixtures/title.rb
- @@ -0,0 +1,5 @@
- +class Title < ActiveRecord::Base
- + belongs_to :user
- + attr_accessible :entity, :entity_id, :title
- + self.primary_keys = :entity, :entity_id, :lang_id
- +end
- diff --git a/test/fixtures/titles.yml b/test/fixtures/titles.yml
- new file mode 100644
- index 0000000..8df48e4
- --- /dev/null
- +++ b/test/fixtures/titles.yml
- @@ -0,0 +1,11 @@
- +title_1:
- + entity: 'agelimits'
- + entity_id: 1
- + lang_id: 1
- + title: '16+'
- +
- +title_2:
- + entity: 'shows'
- + entity_id: 1
- + lang_id: 1
- + title: 'Second'
- diff --git a/test/test_different_types.rb b/test/test_different_types.rb
- new file mode 100644
- index 0000000..b9dbc51
- --- /dev/null
- +++ b/test/test_different_types.rb
- @@ -0,0 +1,11 @@
- +require File.expand_path('../abstract_unit', __FILE__)
- +
- +class TestDifferentTypes < ActiveSupport::TestCase
- + fixtures :titles
- +
- + def test_find_each
- + title = ''
- + Title.where( entity: 'agelimits' ).find_each { |i| title = i.title }
- + assert_equal( title, '16+' )
- + end
- +end
- \ No newline at end of file
Add Comment
Please, Sign In to add comment