Daniel Berger
2006-Feb-28 18:20 UTC
[Rails] Problem with paginate, include and foreign keys
Hi all, Solaris 10 Ruby 1.8.4 Rails 1.0.0 Postgres 8.1 postgres driver 0.7.1 I''m having a problem with getting paginate() to properly pick up an FK constraint properly. I don''t seem to have this issue with ActiveRecord, however. Consider: create table start_dates ( id bigserial, start_date date unique, max_slots int default 40, primary key (id) ); create table schedules ( id bigserial, start_date_id int, ... foreign key (start_date_id) references start_dates (id), primary key (id) ); class StartDate < ActiveRecord::Base has_many :schedules end class Schedule < ActiveRecord::Base belongs_to :start_date end The ActiveRecord portion works as expected: condition = "date_trunc(''day'', start_date) between date(?) and date(?) - 1" Schedule.find( :all, :include => ''start_date'', :conditions => [condition, first,last] ) However, in schedules_controller.rb, this fails: @schedule_pages, @schedules = paginate( :schedules, :include => [''start_date''], :conditions => [condition, first, last] ) PGError: ERROR: column "start_date" does not exist : SELECT COUNT(*) FROM schedules WHERE (date_trunc(''day'', start_date) between date(''2006-2-01'') and date(''2006-3-01 - 1'') - 1) What am I doing wrong here? Thanks, Dan
Mark Reginald James
2006-Feb-28 18:44 UTC
[Rails] Re: Problem with paginate, include and foreign keys
Daniel Berger wrote:> However, in schedules_controller.rb, this fails: > > @schedule_pages, @schedules = paginate( > :schedules, > :include => [''start_date''], > :conditions => [condition, first, last] > ) > > PGError: ERROR: column "start_date" does not exist > : SELECT COUNT(*) FROM schedules WHERE (date_trunc(''day'', start_date) > between date(''2006-2-01'') and date(''2006-3-01 - 1'') - 1)You may need this plugin: http://wiki.rubyonrails.com/rails/pages/Count+Limit+Associations+Plugin -- We develop, watch us RoR, in numbers too big to ignore.
Daniel Berger
2006-Feb-28 19:20 UTC
[Rails] Re: Problem with paginate, include and foreign keys
Mark Reginald James wrote:> Daniel Berger wrote: > >> However, in schedules_controller.rb, this fails: >> >> @schedule_pages, @schedules = paginate( >> :schedules, >> :include => [''start_date''], >> :conditions => [condition, first, last] >> ) >> >> PGError: ERROR: column "start_date" does not exist >> : SELECT COUNT(*) FROM schedules WHERE (date_trunc(''day'', start_date) >> between date(''2006-2-01'') and date(''2006-3-01 - 1'') - 1) > > > You may need this plugin: > http://wiki.rubyonrails.com/rails/pages/Count+Limit+Associations+Plugin >That looks like it will do the trick. Thanks, Dan
Daniel Berger
2006-Feb-28 19:57 UTC
[Rails] Re: Problem with paginate, include and foreign keys
Mark Reginald James wrote:> Daniel Berger wrote: > >> However, in schedules_controller.rb, this fails: >> >> @schedule_pages, @schedules = paginate( >> :schedules, >> :include => [''start_date''], >> :conditions => [condition, first, last] >> ) >> >> PGError: ERROR: column "start_date" does not exist >> : SELECT COUNT(*) FROM schedules WHERE (date_trunc(''day'', start_date) >> between date(''2006-2-01'') and date(''2006-3-01 - 1'') - 1) > > > You may need this plugin: > http://wiki.rubyonrails.com/rails/pages/Count+Limit+Associations+Plugin >I''m a bit confused on how to install this plugin. I created a vendor/plugin/count_limit_association subdirectory, and put both the count_limit_association.rb file and init.rb file under that directory. However, now Webrick dies immediately upon startup, with nary a log entry in site. Was that not the correct way to set it up? Regards, Dan
Mark Reginald James
2006-Feb-28 20:48 UTC
[Rails] Re: Problem with paginate, include and foreign keys
Daniel Berger wrote:> Mark Reginald James wrote: >> You may need this plugin: >> http://wiki.rubyonrails.com/rails/pages/Count+Limit+Associations+Plugin > > I''m a bit confused on how to install this plugin.cd <APP_ROOT> script/plugin install http://jthopple.textdriven.com/svn/public/rails/plugins/count_limit_associations -- We develop, watch us RoR, in numbers too big to ignore.
Daniel Berger
2006-Feb-28 21:03 UTC
[Rails] Re: Problem with paginate, include and foreign keys
Mark Reginald James wrote:> Daniel Berger wrote: > >> Mark Reginald James wrote: >> >>> You may need this plugin: >>> http://wiki.rubyonrails.com/rails/pages/Count+Limit+Associations+Plugin >> >> >> I''m a bit confused on how to install this plugin. > > > cd <APP_ROOT> > script/plugin install > http://jthopple.textdriven.com/svn/public/rails/plugins/count_limit_associations > >Excellent, thank you! The plugin works great, btw. Thanks, Dan