I have a Map
model, which defines the details for an ASCII-art map for a given area in a MUD. I want to be able to reach each map's page using its name instead of its ID, so if I have a map of the Western Ithmia, I want to be able to access it from /maps/western_ithmia
(but also /maps/withmia
).
I have a second model, MapAlias
, which contains all of the existing shortnames that can be used in a path to reach a map. A foreign key is stored with each alias, referring to the ID of its associated Map
.
What I want to do is create a new MapAlias
simultaneously with each newly-created Map
. Unfortunately, it doesn't seem like I can get at my new Map
's ID until it's been saved, but I don't want to save it until I've validated/saved its new MapAlias
. What makes this worse is that I want each Map
to have knowledge of which MapAlias
is its primary alias, i.e. the one that generated links will refer to. This seems like a circular dependency to me...
I'm still pretty new to Rails, so I'm not sure what I should be doing, but I've explored model callback hooks (like before_save) with only limited success - I still have the circular dependency to deal with. Any ideas? =/