Tuesday, February 7, 2012

Re: Generic relationships between existing entities, many2many

On Tue, 7 Feb 2012 19:11:01 +0000, "arkaitzj@gmail.com"
<arkaitzj@gmail.com> wrote:

>Hi,
>
>So, I have the 4 entities represented below which are strong and
>independent entities on my application, now the problem is that each
>Article or Picture could be "tagged" with a Presenter or an Event, being as
>they are the 4 of them independent entities that could become more complex

Parsing your description into boolean logic I'm seeing

(Article xor Picture) and (Presenter xor Event)

which brings up concerns... Can you have a Presenter AT Event
situation? If so, I'd suggest the right half is an intersect table of:

PE_Intersect
ID autonumber,
PresenterID foreign key (Presenter.ID),
EventID foreign key (Event.ID),
unique key (PresenterID, EventID),
constraint (PresenterID not Null or EventID not Null)

(The constraint is just to avoid creating intersections where both
presenter and event are unknown. A single Null covers the case of just a
Presenter or just an Event.)

That still leaves the Article, Picture side... Now, can Pictures be
linked with Articles? Many pictures per article? (one article -> many
pictures). Many articles per picture? Many to Many?

AP_Intersect
replace "Presenter" with "Article"
replace "Event" with "Picture"

(Similar idea, a single Null indicates Picture with no Article, or
Article with no Picture.)

and finally, link the intersect tables with

AP_PE_Intersect
ID autonumber,
APID foreign key (AP.ID),
PEID foreign key (PE.ID),
unique key (APID, PEID)

Given, say, an Event, you would retrieve all PE_Intersect records
with that Event ID. From this you can now retrieve the AP_PE_Intersect
records to find the AP_Intersect records associated with it, and from
that you can retrieve Article and/or Picture records.


Coding this three level intersection in Django is beyond my purview
<G>
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

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

No comments:

Post a Comment