I''m throwing sql errors on a User.find_or_create_by_foo_and_email call. I created an index with the following: add_index "users", ["foo_id", "email"], :name => "by_foo_email", :unique => true Then in a class foo instance method: user = User.find_or_create_by_foo_id_and_email (self.id,some_email_address) and I get this error: ActiveRecord::StatementInvalid (Mysql::Error: Duplicate entry ''joe-/E1597aS9LQAvxtiuMwx3w@public.gmane.org'' for key 2: : INSERT INTO `users` (`name`, `unsubscribed`, `updated_at`, `unsubscribed_date`, `user_id`, `bounce_date`, `foo_id`, `email`, `created_at`, `bounced`) VALUES (NULL, 0, ''2009-03-31 16:04:51'', NULL, NULL, NULL, 11, ''joe-/E1597aS9LQAvxtiuMwx3w@public.gmane.org'', ''2009-03-31 16:04:51'', 0) Isn''t find_or_create_by() supposed to only create if it can''t find? caveat - I''m running this with workling/starling. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Donald
2009-Apr-01 21:31 UTC
Re: find_or_create_by_foo_and_bar error (duplicate entry)
On Wed, Apr 1, 2009 at 10:18 AM, klochner <klochner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m throwing sql errors on a User.find_or_create_by_foo_and_email > call. > > I created an index with the following: > add_index "users", ["foo_id", "email"], :name => > "by_foo_email", :unique => true > > Then in a class foo instance method: > > user = User.find_or_create_by_foo_id_and_email > (self.id,some_email_address) > > and I get this error: > ActiveRecord::StatementInvalid (Mysql::Error: Duplicate entry > ''joe-/E1597aS9LQAvxtiuMwx3w@public.gmane.org'' for key 2: : INSERT INTO `users` (`name`, > `unsubscribed`, `updated_at`, `unsubscribed_date`, `user_id`, > `bounce_date`, `foo_id`, `email`, `created_at`, `bounced`) VALUES > (NULL, 0, ''2009-03-31 16:04:51'', NULL, NULL, NULL, 11, > ''joe-/E1597aS9LQAvxtiuMwx3w@public.gmane.org'', ''2009-03-31 16:04:51'', 0) > > Isn''t find_or_create_by() supposed to only create if it can''t find?I think that''s just for the primary key. -- Greg Donald http://destiney.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?hl=en -~----------~----~----~----~------~----~------~--~---