Add support for "Conditional" references and reference sets

Bug #415757 reported by James Henstridge
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Storm
New
Undecided
Unassigned

Bug Description

Yesterday vds asked me if Storm included a way to do "conditional references". This is a case where the foreign key relationship is one to many, but there is some flag for selecting a single item from that set (e.g. a boolean value, comparing a date field, etc). Often such a relationship would be accompanied by a database level conditional unique index.

I'd imagine that this feature could be useful for Launchpad too: an obvious example would be a person's preferred email address. The Person <-> EmailAddress relationship is one to many, but at most one of those address can be in the PREFERRED state. I'd imagine this case could look something like:

    preferred_email = Reference(id, EmailAddress.person,
        EmailAddress.status == EmailAddressStatus.PREFERRED, on_remote=True)

I realise that not all features of Reference() would make sense in t his case, but enough of them would to make it useful. Things that should work:

1. Reference.__get__(): Would need to use the store.find() code path rather than store.get(). Would need to add the extra conditionals to where clause.

2. caching of linked object: should work same as before: break relation if either object changes.

3. expression builder for "Reference == obj": Same as now, but have to make sure obj satisfies additional conditions. Checking with compile_python.get_matcher() would work for simple conditions.

Things that don't have obvious answers:

1. Reference.__set__(): setting foreign key on new object is easy. Making the object meet extra conditional expression is hard.

2. Unsetting reference: do you unset the foreign key, or do something to make the extra conditional expression fail?

Revision history for this message
James Henstridge (jamesh) wrote :

See also bug 490280

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.