samedi 21 mars 2015

Rails app with postgresql; query with .take does not keep the order of records

I have a rails 4 application and I recently switched from SQlite to Postgresql. I have the following 3 models;



class User < ActiveRecord::Base
has_many :user_games
has_many :games, :through => :user_games
end

class Game < ActiveRecord::Base
has_many :user_games
has_many :users, :through => :user_games
end

class UserGame < ActiveRecord::Base
belongs_to :user
belongs_to :game
end


with the records:



game
id
1

userGame
id user_id game_id
1 5 1
2 3 1

user
id
1
2


I could do this with sqlite:



game = Game.Find(1)
game.users.take(2).first


which would return User with id 5.


The same code with postgres gives user with id 3.


Why?


Aucun commentaire:

Enregistrer un commentaire