# Polymorphic naming difficulties

**URL:** <https://www.ruby-forum.com/t/polymorphic-naming-difficulties/137426>\
**Category:** Rails\
**Created:** [May 13, 2008, 2:24am UTC](https://www.ruby-forum.com/t/polymorphic-naming-difficulties/137426 "2008-05-13T02:24:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dewie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@dewie](https://www.ruby-forum.com/u/dewie)\
**Post date:** [May 13, 2008, 2:24am UTC](https://www.ruby-forum.com/t/polymorphic-naming-difficulties/137426/1 "2008-05-13T02:24:12Z")

</div>

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  
fits.

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!
