User.first and User.last gives Second User instead of Admin user created by seed
dharin opened this issue · 1 comments
If I am creating another user after default admin user(created by seed) and gives User.first or User.last in "rails c", it gives me second user in the users table and not the admin user. I am using Postgresql.
1.9.3-p327 :028 > User.all
User Load (0.8ms) SELECT "users".* FROM "users"
=> [User id: 2, email: "something", encrypted_password: "something", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2013-06-22 06:42:25", last_sign_in_at: "2013-06-22 06:42:25", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2013-06-22 06:42:25", updated_at: "2013-06-22 06:42:25", name: "something",
User id: 1, email: "admin@example.com", encrypted_password: "something", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 2, current_sign_in_at: "2013-06-22 06:43:28", last_sign_in_at: "2013-06-22 06:38:35", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2013-06-22 06:37:51", updated_at: "2013-06-22 06:43:28", name: "Dharin Rajgor"]
and now
1.9.3-p327 :029 > User.first
User Load (0.9ms) SELECT "users".* FROM "users" LIMIT 1
=> User id: 2, email: "something", encrypted_password: "something", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2013-06-22 06:42:25", last_sign_in_at: "2013-06-22 06:42:25", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2013-06-22 06:42:25", updated_at: "2013-06-22 06:42:25", name: "something"
1.9.3-p327 :030 > User.last
User Load (0.9ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
=> User id: 2, email: "something", encrypted_password: "something", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2013-06-22 06:42:25", last_sign_in_at: "2013-06-22 06:42:25", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2013-06-22 06:42:25", updated_at: "2013-06-22 06:42:25", name: "something"
Found the Solution. My first Record is updated more recently then second Record and when I set the updated_at to most recently for second record, it started working.. It's quite strange but true !!!