Jon Cox wrote:
> ooh found 'has_many_and_belongs_to' in ActiveRecord that takes care of
> the match->match_game<-game relationship nicely!
The current trend in Rails is toward has_many :through instead of
has_and_belongs_to_many (HABTM). The has_many :trough is more flexible,
and often more RESTful.
Imagine what happens if you need to store something that relates to a
particular game of a match. You can't store that in either the matches
nor the games tables. You would instead need access to the joining table
match_games.
class Match << ActiveRecord::Base
has_many :match_games
has_many :games, :through => :match_games
end
class Game << ActiveRecord::Base
has_many :match_games
has_many :matches, :though => :match_games
end
class MatchGame << ActiveRecord::Base
belongs_to :match
belongs_to :game
end
Again write your stories and use them to drive your design. This is
opposed to trying to build your application from the perspective of the
data model. Letting your acceptance criteria drive your design will
develop into a better user experience. You'll be concentrating on what
the user sees, and how they interact with your application. I think
you'll find that the model almost takes care of itself as you write code
to make your stories (and specs) pass.
Feature: player starts a new match
As a player
I want to start a new match
So that I can have fun fragging my friends
Scenario: starting a match
Given a new match
When I start the match
Then I should <fill in what you expect to see (or happen)>
And I should <fill in other things you expect when starting a match>
Scenario: <continue writing your acceptance criteria and let that
drive your design>
Given ...
When ...
Then ...
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.