Design Decision Required: Plural Names for Many-to-Many Associations

7 views
Skip to first unread message

james....@googlemail.com

unread,
Jan 27, 2011, 9:44:05 AM1/27/11
to Outlet ORM
I have just been coding for the following situation:

A User can be a Member of many Teams, and each Team may have many
Members (Users).

The association is a many-to-many relationship between class Team and
class User, although the name of the relationship is "Member" (A Team
has members (users), and users are members of a team).

I have set my config file up to handle this relationship as a many-to-
many relationship between Team (local) and User (foreign), with
"Members" as the plural name for the association.

I note that the Outlet documentation specifies that the many-to-many
association has the following configuration options: table,
tableKeyLocal, tableKeyForeign and plural. The Outlet documentation
does NOT list "name" as a config option for many-to-many association
options.

When I attempted to load a bunch of Teams from the database, however,
Outlet returned an error to the effect that the method: "setUsers()"
was undefined. This implied that Outlet was using the entity name for
the association (i.e. Users), rather than the specified plural name.

Some debugging showed this to be the case, and the reason can be
traced back to the getForeignPlural() method in the
OutletAssociationConfig class:

if (isset($this->options['name'])) {
// if this association has a plural, use that
// else use the name plus an 's'
if (isset($this->options['plural'])) {
$plural = $this->options['plural'];
} else {
$plural = $this->options['name'].'s';
}
// else check the entity definition
} else {
$foreignCfg = $this->config->getEntity($this->foreign);

$plural = $foreignCfg->plural;
}
return $plural;

The code requires that the 'name' option is set, before checking to
see whether or not a plural name is specified. In the case of a many-
to-many relationship, the Outlet documentation specifies that this
option does not need to be specified.

The problem then is that the code is at odds with the documentation.

I have resolved my particular issue by simply adding the name option
to all many-to-many associations in my config file. However, a clear
and long-term design decision needs to be made.

Either the documentation needs to be updated so that the name option
is required for many-to-many associations, or the issue needs to be
treated as a bug and updated to take account of the possibility that
the plural option is specified, but the name option is not.

Luís Otávio

unread,
Jan 27, 2011, 1:24:58 PM1/27/11
to outle...@googlegroups.com
On my fork (https://github.com/lcobucci/outlet-orm) I've made a little change on this.

I check both for name and plural. First using name, and then if plural is defined I use plural (because the name is not on Outlet documentation).
If name and plural is not defined I use the foreign entity's plural (like is in svn trunk).

Look there to see if you like. There's a lot of changes, but the main usage it's not so different than the svn trunk.


Luís


--
You received this message because you are subscribed to the Google Groups "Outlet ORM" group.
To post to this group, send email to outle...@googlegroups.com.
To unsubscribe from this group, send email to outlet-orm+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/outlet-orm?hl=en.


mindplay.dk

unread,
Jan 28, 2011, 10:03:19 AM1/28/11
to Outlet ORM
Dear Programmers,

I will never understand why developers are so keen on inflection in
the first place - all this work to solve the problem of having to
manually type in the plural form of a model's name somewhere.

Problems:

- Typically only works for english.
- Frequently fails for irregular words.
- Requires an inflector; most (if not all) have imperfections
- You still need to manually handle edge cases where regular english
doesn't work for some reason

Net gains:

- You save an average of 8-10 keystrokes per model you build.

Did I leave anything out?

Conventions are good, but the problem with inflection is, you're
trying to operate on human language (english) rather than computer
language. Your class names and certain keywords may be english, but
your compilers do not understand english, nor human language of any
kind, they just interpret keywords, identifiers, operators,
constructs.

Regardless of how hard you try to maintain your illusions, your
compiler just doesn't know what you're talking about. Your words are
just symbols, and will not be interpreted as more than that - all your
efforts are in vain.

I don't understand why everyone insists on struggling with this, just
so they can type "user" instead of "user,users" in that one line of
code somewhere. Save yourself the trouble, and give me a line of code
where I can actually see how you're naming your objects and
collections, please!

Your logic does not compute!

</rant>


On Jan 27, 9:44 am, "james.a.na...@googlemail.com"

james....@googlemail.com

unread,
Jan 29, 2011, 12:51:12 PM1/29/11
to Outlet ORM
I *think* this is exactly the point I make in my original post. At
present, Outlet checks to ensure that *name* is specified and only if
it is, does it check for *plural*. Since the relevant code is in a
method called getForeignPlural, I see no reason why the method needs
to check for *name* at all - *name* is intended to apply only to the
singular association.

In other words, what would be wrong with rewriting the
getForeignPlural method as follows:

if (isset($this->options['plural'])) {
$plural = $this->options['plural'];
} else {
if (isset($this->options['name'])) {
$plural = $this->options['name'].'s';
} else {
$foreignCfg = $this->config-
>getEntity($this->foreign);
$plural = $foreignCfg->plural;
}
}
return $plural;

That is, use the plural option if specified. If it isn't specified,
use the name option and append 's'. If name isn't specified, use the
entity's plural name.

On Jan 27, 6:24 pm, Luís Otávio <lcobu...@gmail.com> wrote:
> On my fork (https://github.com/lcobucci/outlet-orm) I've made a little
> change on this.
>
> I check both for *name* and *plural*. First using *name*, and then if *
> plural* is defined I use *plural* (because the *name* is not on Outlet
> documentation).
> If name and plural is not defined I use the foreign entity's plural (like is
> in svn trunk).
>
> Look there to see if you like. There's a lot of changes, but the main usage
> it's not so different than the svn trunk.
>
> Luís
>
> On Thu, Jan 27, 2011 at 12:44 PM, james.a.na...@googlemail.com <
> > outlet-orm+...@googlegroups.com<outlet-orm%2Bunsubscribe@googlegrou ps.com>
> > .
Reply all
Reply to author
Forward
0 new messages