This project is archived and is in readonly mode.
ActiveRecord exists? won't work with keyless tables
-
Tom Ward
Can you provide a failing test case? The solution is pretty simple (select 1 rather than select primary_key), but in what circumstance would you actually have an ActiveRecord class without a primary key?
-
Pratik
- State changed from new to wontfix
I wonder what actually works when you don't have a PK. In any case, you should just write a plugin overriding exists?
-
fearless_fool
- Importance changed from to
Is there a good explanation for the wontfix status? Specifically, it is surprising that AR.exists?() fails on PK-less tables, given that AR.find() works just fine.
> UserRole.find(:first, :conditions => {:user_id => 4, :role_id => 2}) => #
Of course you can emulate AR.exists?() as:
> !!UserRole.find(:first, :conditions => {:user_id => 4, :role_id => 2}) => true
- ff
P.S.:
create_table "user_roles", :id => false, :force => true do |t|
t.integer "user_id" t.integer "role_id"end
and
$ rake about About your application's environment
Ruby version 1.9.2 (x86_64-darwin10.4.0)
RubyGems version 1.3.7
Rack version 1.2
Rails version 3.0.0
Active Record version 3.0.0
Action Pack version 3.0.0
Active Resource version 3.0.0
Action Mailer version 3.0.0
Active Support version 3.0.0
Application root /Users/ff/Developer
Environment development -
fearless_fool
- Tag changed from 2.1, activerecord, bug to 3.0, activerecord, bug
Doh - once again with formatting...
> UserRole.find(:first, :conditions => {:user_id => 4, :role_id => 2}) => #<UserRole user_id: 4, role_id: 2>Of course you can emulate AR.exists?() as:
> !!UserRole.find(:first, :conditions => {:user_id => 4, :role_id => 2}) => trueP.S.: Since this was originally a 2.1 ticket, please let me know if I should open a new ticket altogether for 3.0...