Hi (again) Rickard,
Sorry, I was having trouble seeing it, but I played with a model and think I
know what you are doing now.
Given the fact A has B, both roles optional, and both roles (individually)
unique you have some options:
1) The mapping algorithm will arbitrarily make B an attribute of the A table
or visa versa.
2) If either role is mandatory, the mapping algorithm will map the
attributes such that the table with the mandatory role gets the attribute,
thus solving your uniqueness constraint problem.
3) You could nest this fact, declare it independent, and thus get an
intersection entity. It sounds like you did this, correct?
Now for the "just my opinion" part:
Option 3 is a good idea if the nested object plays roles itself in some
fact(s). Otherwise, it isn't the worst idea, especially if A and B end up
being distinct tables (i.e. they both play functional roles with other
objects and thus map as tables with some sort of relationship between them).
If B (or A) don't map as their own tables, the independent nested object in
effect creates a table who's sole purpose is to house an attribute such that
the uniqueness constraint can more easily be enforced via a SQL database.
I'm not a fan of this approach. I think simple trigger code enforcing
uniqueness over non-null values could do the same job if B were a nullable,
non unique index bound attribute of A.
I would probably lean towards that (trigger) approach even if A and B were
tables by themselves, but I would have to consider other factors such as:
1) How sure am I that neither role is mandatory?
2) How sure am I about the 1:1 relationship?
3) Are either of the above due to other design time decisions that could be
altered to meet their original requirements and not end up with these
awkward constraints? By this, I mean are A or B some artificial thing that
got added as a physical implementation detail or other non-business related
factor?
4) How stable are these rules (how likely are they to change in the next
year)?
If the root of your question is "am I doing anything that violates some ORM
rule?", then I'd have to say probably not. If it's "is this a best
practice?" then I'd have to say: it depends. ; )
Hope that helps,
Scot.
................................................
Scot Becker
Orthogonal Software
www.orthogonalsoftware.com
ORM Blog:
www.objectrolemodeling.com
To e-mail me, please use my first name at the domain listed above. All mail
sent to the reply-to address gets routed to a junk e-mail folder where it
will likely be deleted without being read.