I have a model named User. When running this application from the console I can call User.find_by_id(nil) and it returns nil. When running this application during testing or through WEBrick or Mongrel calling User.find_by_id(nil) returns the newest record in the database. But it only does this the first time you call it with nil. The second time you call User.find_by_id(nil) it returns nil. I know this is how it works running against Edge Revision 4599. But I think I was seeing the same behavior against Rails 1.1.2 Is this expected? Is this a known issue? Thanks, Matt Griffith http://mattgriffith.net -- Posted via http://www.ruby-forum.com/.
What is your DBMS? If it is MySQL, the reason why User.find_by_id(nil) returns the newest record may be the following feature. http://dev.mysql.com/doc/refman/5.1/en/create-table.html :> To make MySQL compatible with some ODBC applications, you can find the > AUTO_INCREMENT value for the last inserted row with the following query: > > SELECT * FROM tbl_name WHERE auto_col IS NULL-- Yugui yugui.ps@gmail.com http://idm.s9.xrea.com
Matt Griffith
2006-Jul-14 14:55 UTC
[Rails] Re: find_by_id(nil) does not always return nil
Yugui wrote:> What is your DBMS? If it is MySQL, the reason why User.find_by_id(nil) > returns the newest record may be the following feature.MySQL is the only database I''ve verified the error against. I think I''ve seen the same symptoms on SQLite3 though. I''ll run some more tests and see if I can narrow it down. Thanks for the pointer. Matt Griffith http://mattgriffith.net -- Posted via http://www.ruby-forum.com/.