Polymorphic naming difficulties

Hi all. I’m having a problem naming a polymorphic relationship. Here’s
my thinking…

First, an analogy. You’re walking through the mall. Through a window you
see a game you’re interested. I’m attempting to model the relationship
between your interest and the game you’re interested in.

I have an InterestList. It’s job is to maintain a collection of Interest
objects. Interest objects “point to” the thing they are interested in.

I have InventoryPrototype objects. Think of these as “shelf models” in a
store. They’re tell you everything you want to know about your intended
purchase, but they themselves are not for sale.

The Interest objects “belong to” the InventoryPrototype objects.

InventoryPrototype objects utilize STI so that different products can
exhibit different behaviors. I have, for instance, a
GiftBoxInventoryPrototype, which behaves slightly differently when added
to an InterestList. But that’s off-topic for the question.

From the perspective of the product, it makes sense for it to say, “I
have many onlookers”. I liked it so much I coded it…

class InventoryPrototype
has_many :onlookers

But InventoryPrototype utilizes STI. It also collaborates with objects
that to not descend from InventoryPrototype, so the Interest object must
be polymorphic.

class Interest
belongs_to :???, :polymorphic => true

Upon further thought, I figured “purchasable” makes sense from
Interest’s perspective:

class Interest
belongs_to :purchasable, :polymorphic => true

An interest belongs to something purchasable. Not ideal, but it kind of

But now the owning relationship makes no sense:

class InventoryPrototype
has_many :onlookers, :as => :purchasable

An InventoryPrototype has many onlookers as purchasables?

If you’re curious, I’m modeling a “shopping cart”-type domain. I doubt
it looks like a shopping cart to most people, but I think it more
accurately reflects the problem domain to break it up like this.

I’m almost wondering if I’ve hit some metaphorical limit between what
the domain expresses and what Rails can (inherently) express.

Anywho, query me if you need more clarification.

Thanks, much!

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