Forum: Ruby on Rails Naming join models

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
17acfbd3a05cfb59e0543235cc0a813b?d=identicon&s=25 Joshua Susser (Guest)
on 2006-02-18 20:03
(Received via mailing list)
I've been playing around with EdgeRails and checking out some of the
new features.  The one that will probably have the biggest affect on
my designs is join models (or :through associations).  For those not
familiar with this feature, it lets you replace your habtm
association with a pair of has_many associations indirected through
an intermediate model class.

Looks like good stuff.  The thing that makes me cry is trying to name
the darn join model classes.  In his Pursuit Of Beauty presentation,
DHH uses the example of an Authorship join model class to represent
the association of an Author and a Book, and a Tagging for a Taggable
and a Tag.  Those examples are fairly readable, but I'm noticing that
many other relationships are harder to name.  I think the problem is
trying to turn a verb-type relationship into a noun-type reification
of that relationship.

For example, what do you call the reification of the relationship of
a Participant to a Meeting?  A "Participation"?  An "Attendance"?
What about a Student to a SchoolClass?  A ProjectManager to a
Project?  Start pluralizing and things get even uglier.  Naked join
tables have their drawbacks, but at least they are easy to name.

I suppose I could name a class ParticipantEventJoin to get a table
participant_event_joins.  While that would make things very obvious
it lacks a certain charm.  Maybe there is a better formula for coming
up with a standard name.  Any ideas?

--joshua susser
1e99128ebac5ca41c91940291d315332?d=identicon&s=25 Luke Redpath (Guest)
on 2006-02-19 03:17
If you are seriously struggling to find a name, it could be a sign that
your join doesn't really need to be a model.

First, your participant/meeting example. I think what you have here is a
case of a mis-named model. People attend meetings, not Participants. A
person only becomes a participant once they go to a meeting.

You can always try approaching it this way. What does object x do to
object y?

A person *attends* a meeting.

Person > Attendance < Meeting

In order to attend a class, a student must enroll.

Student > Enrollment < SchoolClass

A project manager is assigned to a project.

ProjectManager > Assignment < Project

Maybe, an employee only becomes a project manager when they are assigned
to a project:

Employee > Assignment < Project

In the above, as well as linking together an employee and a project, the
Assignment model also holds details of the assignment type (developer,
manager).

Ultimately, if you are really struggling with a name, it might just be a
same that you don't need a join model, all you need is a simple habtm
relationship and a plain jane join table.

Cheers
Luke Redpath

> For example, what do you call the reification of the relationship of
> a Participant to a Meeting?  A "Participation"?  An "Attendance"?
> What about a Student to a SchoolClass?  A ProjectManager to a
> Project?  Start pluralizing and things get even uglier.  Naked join
> tables have their drawbacks, but at least they are easy to name.
>
> I suppose I could name a class ParticipantEventJoin to get a table
> participant_event_joins.  While that would make things very obvious
> it lacks a certain charm.  Maybe there is a better formula for coming
> up with a standard name.  Any ideas?
>
> --joshua susser
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-07-03 17:18
(Received via mailing list)
Hi,

Now that we are headed for the CRUD-for-everything interface, it seems
like naming join models has a little more importances as the user will
even more likely see the join model name.

Sometimes the join model is needed just to make ordering the items
easier using acts_as_list in the join model. I don't have the naming
thing figured out yet either.

On 2/18/06, Joshua Susser <joshua@tiralorn.com> wrote:
> The thing that makes me cry is trying to name
> the darn join model classes.

On 2/18/06, Luke Redpath <contact@lukeredpath.co.uk> wrote:
> If you are seriously struggling to find a name, it could be a sign that
> your join doesn't really need to be a model.


Some examples I've seen with good names (all related to people):

Author > Authorship < Book
Reader > Readership < Book
Reader > Reading < Article
Person > Membership < Group
Person > Attendance < Meeting
Student > Enrollment < SchoolClass
Employee > Assignment < Project
Person > Registration < Conference

Some examples I have. Any suggestions?

Product, Person > Visualization [polymorphic] < Images
Category > Categorization < Product

A t-shirt has red or green versions with a SKU each
Product > ? < Variation

A computer has a cpu and hard drive
Product > ? < Part

A user as particular role permissions
User> ? <Role

A user has particular additional permissions
User > Abilities? < Permission

Can you add to the list?

Thanks,
Peter
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-07-23 07:13
(Received via mailing list)
On 7/3/06, Peter Michaux <petermichaux@gmail.com> wrote:
> Person > Attendance < Meeting
> Student > Enrollment < SchoolClass
> Employee > Assignment < Project
> Person > Registration < Conference
>
> Some examples I have. Any suggestions?
>
> Product, Person, etc > Visualization [polymorphic] < Images
>
> Category > Categorization < Product

Department > Placement < Product


> A t-shirt has red or green versions with a SKU each
> Product > ? < Variation

???


> A computer has a cpu and hard drive
> Product > ? < Part

Product > Part < Product


> A user as particular role permissions
> User> ? <Role

User > Role < Task


> A user has particular additional permissions
> User > Abilities? < Permission

User > Permission < Task



Maybe I'm getting a little better at this.

Peter
5ac4033486edab2e9059ca1ccf13c8fa?d=identicon&s=25 Jordan McKible (jmckible)
on 2006-07-23 07:54
I posted on this same topic earlier in week:

http://www.ruby-forum.com/topic/73517

I'm running into problems when model objects don't represent real world
things.  My model objects (like Views -> Filters -> Groups) only make
sense in the context of my app.  There is no english word (especially
not a noun) for the relationship of a View to a Filter.

I'm going with the ViewFilter class name, but I'm not thrilled about it.
There's no good reason it couldn't be called FilterView.  One of the
nice things resulting from CRUD design is simplified urls.  Awkward
relationship names make for awkward urls.

In the grand scheme of things this doesn't really matter, but it seems
like there should be an elegant solution.
Cb2b768a5e546b24052ea03334e43676?d=identicon&s=25 Dr Nic (nicwilliams)
on 2006-07-23 10:31
BTW, http://hasmanythrough.rubyforge.org is useful for generating the
join model with unit tests etc.
Aa4b0ed5d6ec3887e601531325c10e7e?d=identicon&s=25 Adam (Guest)
on 2006-09-21 00:27
Interesting how you find a useful conversation like this AFTER you have
resolved your problem.

Im starting a list of example join tables for RESTful applications, ive
showen my approach and listed some of the examples from the comments
above.

http://railsnotes.blogspot.com/
' Naming join models for RESTful applications '
This topic is locked and can not be replied to.