Operand should contain 1 column(s)
Reported by James Herdman | June 26th, 2007 @ 05:09 AM
I have a model like this
class Admin < User
has_many :places, :finder_sql => 'SELECT * FROM places' do
def find(*args)
Place.find(*args)
end
end
# etc
end
Note the has_many extension. If I try to use any finder method it works just fine. However, paginate is puking:
> a = Admin.find(:first)
=> ( some admin object )
> a.places.find(:all)
=> ( lots and lots of results )
> a.places.paginate(:all, :page => 1)
ActiveRecord::StatementInvalid: Mysql::Error: Operand should contain 1 column(s): SEL
ECT count(*) AS count_all FROM places WHERE (( SELECT * FROM places ) AND ( places.de
leted_at IS NULL OR places.deleted_at > '2007-06-21 18:43:54' ))
This same error occurs if I manually specify the counter_sql option as well.
Comments and changes to this ticket
-
James Herdman June 26th, 2007 @ 05:09 AM
Slight update.
Part of the SQL involved is clearly from the Acts_As_Paranoid plugin. If you rip this out you get the same error with SQL like:
SELECT count(*) AS count_all FROM places WHERE ( SELECT * FROM places )
Same error though. How is WP counting? I can't quite track it down in the code.
-
James Herdman June 26th, 2007 @ 05:09 AM
I'm still working on hunting down this bug, but I thought I'd post some progress. Attached is a modified copy of the will_paginate plugin that uses an STI relationship:
User -> Admin
User -> Developer
If you run the tests for the attached you'll see two errors: ignore the first one for the join tests. The second error is exactly what I'm getting -- but I use MySQL in my development environment instead of SQLite3.
Any ideas?
-
Chris Wanstrath June 26th, 2007 @ 05:09 AM
- State changed from new to open
- Assigned user changed from Chris Wanstrath to Mislav
-
Chris Wanstrath June 26th, 2007 @ 05:09 AM
- State changed from open to invalid
(from [277]) Will Paginate: User-Admin-Developer now in STI. [#43 state:invalid]
-
Mislav June 26th, 2007 @ 05:09 AM
James,
I closed this because this is not a valid use case.
class Admin < User has_many :places, :finder_sql => 'SELECT * FROM places' do def find(*args) Place.find(*args) end end end
First of all, this "association" doesn't make any sense. Second, you're using the :finder_sql option, which means WP will probably be unable to count by itself. You'll have to pass the count in the :total_entries option.
While your result SQL is certainly strange, you'll have to do 2 things before reopening this ticket: 1) use edge Rails and 2) provide a valid use case I can test with.
I've modified existing tests to use STI for User-Developer-Amin. This will make it easier for you to send me a patch with a valid failing test case. Thanks
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป