Created
April 15, 2012 12:58
-
-
Save emil-palm/2392659 to your computer and use it in GitHub Desktop.
Join model assoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class match: | |
has_many :match_maps | |
has_many :maps, :through => :match_maps, :conditions => {'match_maps.veto' => false}, :source => :map, :class_name => "Map" | |
has_many :vetos, :through => :match_maps, :conditions => { 'match_maps.veto' => true}, :source => :map, :class_name => "Map" | |
m = Match.find(1) | |
m.vetos << Map.find(1) | |
m.map << Map.find(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
=> #<Map id: 2, name: "asdf", created_at: "2012-04-15 13:16:33", updated_at: "2012-04-15 13:16:33">
1.9.2-p290 :063 > m.vetos << map
(0.1ms) begin transaction
SQL (0.3ms) INSERT INTO "match_maps" ("map_id", "match_id", "veto") VALUES (?, ?, ?) ["map_id", 2], ["match_id", 1], ["veto", nil] commit transaction