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

Daniel B. wrote:

between date(‘2006-2-01’) and date(‘2006-3-01 - 1’) - 1)
You may need this plugin:
Peak Obsession


We develop, watch us RoR, in numbers too big to ignore.

Mark Reginald J. wrote:

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:
Peak Obsession

That looks like it will do the trick.

Thanks,

Dan

Mark Reginald J. wrote:

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:
Peak Obsession

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 J. wrote:

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

Daniel B. wrote:

Mark Reginald J. wrote:

You may need this plugin:
Peak Obsession

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.