krunk-
2006-Dec-04 22:54 UTC
How do I get ActiveRecord::Base create to insert what I tell it to?
Example: Subject.create(:id => 5, :updated_on => ''2006-10-08 5:28:33'') If you look in the db it has: subject: id: 1 updated_on: 2006-12-06 (whatever CURDATE() TIME() is) If I look in the log it has the actual query used as: INSERT INTO `tablName` (updated_on) VALUES (2006-12-06); So we can see that it''s completely ignored the explicit setting of id as well as the value given for updated_on. I did a lot of googling and found this: ActiveRecord::Base.record_timestamps = false Which turns off the ignoring of the updated_on value but this option was pretty heavily burried in the api docs under Timestamp. Is there a way to get create to just insert what I tell it to or should I drop back to db = Mysql.new(*args) db.query(myquery) type stuff when I need to do this? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Roland Mai
2006-Dec-04 23:37 UTC
Re: How do I get ActiveRecord::Base create to insert what I
I think this is a matter of portability. I remember that in MSSQL you can not insert on an identity fields, but in MySQL you can even though the field is set to auto increment. However, it seems that subject = Subject.new(:updated_on => ''2006-10-08 5:28:33'') subject.id = 5 subject.save does what you need. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---