ruby on rails - Find objects in model by relative condition -



ruby on rails - Find objects in model by relative condition -

i`m new ror. please help me: have 2 models:

class user < activerecord::base belongs_to :game end

and

class game < activerecord::base has_many :users, :foreign_key => "game_id" end

game objects have many users. need find game objects, users.count == 1. please help.

a bit long worked me:

game.joins(:users).where("(select count(users.game_id) users users2 users2.game_id = games.id) = 1")

you can utilize includes() or joins() depending on want do.

ruby-on-rails

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -