WanWizard/Datamapper2 — Issue #2: multiple columns for a foreign key in a relationship
Author: WanWizard
Created: 2011-11-08 15:00:27+00:00
State: open

From http://codeigniter.com/forums/viewreply/951568/:

One feature I’d love to see is the ability to use multiple columns for a foreign key in a relationship.

The idea would be for example, you have an ID column, and a class name column, and you use both together to make a relationship to multiple different models.

Here’s a use case:

You have a group, and a group has members. You have two columns: member_id, and member_class. The member class could be a User object, or another Group object (so it would read out “user”, or “group”), but you can access all of them through the members method. It’s good if you have multiple classes that have similar properties (perhaps implementing the same interface) and can all belong to the same object of another class, but might have some other divergent attributes or methods as well (therefore creating the need for subclasses and separate tables).

Another example is a folder object, which can contain image objects and document objects and video objects, etc, but from the perspective of the folder, they are all just files, and you want to treat them in a uniform way.