Hi, I''ve got some information in a new table I''m adding to my system. (I''m not a database person, so forgive my lack of correct terminology.) I was expecting to access the table via fields other than the id field (contribution_id, user_id and/or ip_address), but never by id, so I didn''t create the table with the id field (":id => false" in my create_table call. Anyway, it seemed to work find for creating records. But when I went to modify an object and save it, I got the following error: Mysql::Error: #42S22Unknown column ''id'' in ''where clause'': UPDATE ratings SET `contribution_id` = 27, `user_id` = NULL, `rate_good` = 0, `ip_address` = ''127.0.0.1'' WHERE id = NULL Now if I change my table definition to have an id field (ie, get rid of the ":id => false" clause), everything seems to work fine. Does this sound like a bug, or user-error? If the latter, what am I misunderstanding and what is the fix? Thanks, Brad -- Bradley Mazurek --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Active record just really really wants you to have a primary key (which you don''t have to call id) Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
bradley.mazurek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-21 16:25 UTC
Re: Mysql error when no id column
> Active record just really really wants you to have a primary key (which > you don''t have to call id)Then why would create_table have an ":id => *boolean*" parameter? Should :id be deprecated? Brad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
bradley.mazurek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:>> Active record just really really wants you to have a primary key (which >> you don''t have to call id) >> > > Then why would create_table have an ":id => *boolean*" parameter? > > Should :id be deprecated? > > Brad >because by default, the create table will create an "id" field all by itself. So, you have to set that parameter to ''false'' if you do not want that id field to be created (in which case, you will be required to put in a field that serves as the primary key if you want one) hope this helps, Cheers Mohit. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
bradley.mazurek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-21 17:57 UTC
Re: Mysql error when no id column
If that were the case, then wouldn''t the assignment of the alternative primary key field be a sufficient indicator for the primary key alternative? Brad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
unknown wrote:> If that were the case, then wouldn''t the assignment of the alternative > primary key field be a sufficient indicator for the primary key > alternative? > > BradIf you are using something other than id as your primary key you need to tell activerecord, ie class Widget < ActiveRecord::Base set_primary_key "widget_id" end The ability to turn off the the id column is also useful for join tables. Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---