Forum: Ruby on Rails Problem with paginate, include and foreign keys

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Daniel B. (Guest)
on 2006-02-28 20:22
(Received via mailing list)
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 J. (Guest)
on 2006-02-28 20:46
(Received via mailing list)
Daniel B. wrote:

> between date('2006-2-01') and date('2006-3-01 - 1') - 1)
You may need this plugin:
http://wiki.rubyonrails.com/rails/pages/Count+Limi...

--
We develop, watch us RoR, in numbers too big to ignore.
Daniel B. (Guest)
on 2006-02-28 21:23
(Received via mailing list)
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:
> http://wiki.rubyonrails.com/rails/pages/Count+Limi...
>

That looks like it will do the trick.

Thanks,

Dan
Daniel B. (Guest)
on 2006-02-28 22:00
(Received via mailing list)
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:
> http://wiki.rubyonrails.com/rails/pages/Count+Limi...
>

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. (Guest)
on 2006-02-28 22:48
(Received via mailing list)
Daniel B. wrote:
> Mark Reginald J. wrote:
>> You may need this plugin:
>> http://wiki.rubyonrails.com/rails/pages/Count+Limi...
>
> I'm a bit confused on how to install this plugin.

cd <APP_ROOT>
script/plugin install
http://jthopple.textdriven.com/svn/public/rails/pl...

--
We develop, watch us RoR, in numbers too big to ignore.
Daniel B. (Guest)
on 2006-02-28 23:03
(Received via mailing list)
Mark Reginald J. wrote:
>
> cd <APP_ROOT>
> script/plugin install
> http://jthopple.textdriven.com/svn/public/rails/pl...
>
>

Excellent, thank you!

The plugin works great, btw.

Thanks,

Dan
This topic is locked and can not be replied to.