However, all’s well now and I have a full game loop: That is to say, the player can click on the map to bring up a list of the armies in each city, can order the armies to move to neighbouring cities, and can click ‘submit’ for his orders to be executed. And the armies do move, and the database does get updated, and it is evening and morning the second day. Not very exciting as games go, by any means – the armies don’t fight, or anything, they just move around – but there’s a lot of backend stuff set up that I didn’t have before. What’s more, I now actually understand (at some level) all this database stuff, and (complaints about syntax checking aside) am beginning to feel how powerful Rails really is. Coding even this basic functionality by hand as SQL queries would have taken me weeks.
A minor problem is that there doesn’t seem to be a way for an object of a given class to point to a collection of the same class, only to different classes. You can do has_one, eg
but not has_many:
has_many :foos, :through => association
because there is no way to set the foreign keys in the join table properly. :through will by default guess that the foreign key is foo_id, and then what should it set the other key to? I can’t figure out how to specify this when both targets are the same class. So this has to be coded by hand, or at least I had to do so. Perhaps there is a clever way. But this is a minor complaint.