HABTM Association with STI model

Is there a better way to do this? It looks really ugly!

Are Facility and Unit really both types of GenericUnit? What do they
have in
common? Do they really need the same parent class?

Sorry if this feel as an ‘up’, but I felt I needed to provide a more
thorough explanation about what I want to accomplish.

I’m developing a game set on Star Wars universe. On this game, I’ll have
Squadron that can buy Units to compose Fleets, provide they can (check
a habtm association between Squad and Unit).

But we now need an extra layer of complexity upon this. We have a new
of Unit called Facility, which will produce a kind of Unit. I am
creating a
new class for Fleets composed of Facilities as well.

So, Squad can have Fleets and FacilityFleets (has_many for both), and
on Units and Facilities. What I’ve come up so far is:

I have a GenericUnit which Unit and Facility inherits from, and a
GenericFleet which Fleet and FacilityFleet inherits from. My problem is
I don’t know how to set up these relationships. I’ve stuck on the
GenericUnit/Unit/Facility problem. I’ve kinda solved this as showed
http://pastie.org/1640550. But this doesn’t look like the right way to
this. I’m pretty sure there is a smarter way of doing this.

Thanks for your help!

Thanks for the reply!

And yeah, they are. GenericUnit was actually created to handle the
similarities, after we thought of the Facility type. They can both be
captured, and costs money, are looked upon at when registering attacks,

Code is on http://github.com/lunks/wargame, if you’d like to take a

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs