in

The ORM Foundation

Get the facts!

Help with boolean logic and constraints

Last post 10-28-2010 2:02 by Terry Halpin. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 10-25-2010 11:01

    • subkamran
    • Top 100 Contributor
      Male
    • Joined on 03-25-2010
    • Minneapolis, MN
    • Posts 4

    Help with boolean logic and constraints

    Given these business rules, I am having a hard time conceptualizing how to model this in NORMA:

    • A Class can be active [or inactive]
    • A Class can be primary [or "normal"]
    • A primary class can only be active
    • There can't be more than one primary class

    The end result of some time thinking about this produce an entity of Class (with some other facts), a subtype entity of "Active Class" with a single binary fact "Is Primary" value type (Logical: True or False) hanging off the subtype with a 1:1 role mapping.

    I don't know if that is a good way to do it; I used non-absorbed mapping so we have a separate table for active classes. I had some pushback from team members asking why we needed whole other table and I tried to explain that it enforces the 3rd business rule, but a check constraint on one table with two boolean columns was the argument against that.

    Does anyone have any feelings about either approach?

  • 10-26-2010 3:16 In reply to

    Re: Help with boolean logic and constraints

    It depends a little on the dynamics. Will a non-primary class ever become primary, or vice versa?

    Irrespective of that, I'd probably choose either the two unaries and a subset constraint (maps to a CHECK constraint) or a three-valued value type {'inactive', 'active', 'active primary'}.

    Just be aware that with unary fact types in NORMA, you don't currently have control over whether you mean closed world (true/false), open world (true/unknown) or open world with negation (true/false/unknown). NORMA's interpretation is OW, which to my mind, is the least useful of the three possibilities.

    In my view, this is a weakness in the ORM2 graphical representation.

  • 10-26-2010 9:16 In reply to

    • subkamran
    • Top 100 Contributor
      Male
    • Joined on 03-25-2010
    • Minneapolis, MN
    • Posts 4

    Re: Help with boolean logic and constraints

    Clifford Heath:

    It depends a little on the dynamics. Will a non-primary class ever become primary, or vice versa?

    Yes, in fact, in the future there could be multiple primaries.

    I think the 3-state logic is an interesting idea. We could create 3 views to show active, inactive, and primary-active classes.

  • 10-27-2010 8:54 In reply to

    Re: Help with boolean logic and constraints

    Like Clifford, I would typically use either two unaries, or one binary to a 3-valued type.

    For the unary approach, run a subset constraint from is-primary to is-active. In ORM (but not yet NORMA) you could capture the constraint that at most one class is primary by adding a role cardinality constraint of #<=1 to is-primary.

    For the binary approach, I would use the names active-primary, active-normal, and inactive. The restricted uniqueness constraint (active-primary applies to at most one class) would then have to be added manually as a textual constraint.

    Cheers

    Terry

  • 10-27-2010 11:35 In reply to

    • subkamran
    • Top 100 Contributor
      Male
    • Joined on 03-25-2010
    • Minneapolis, MN
    • Posts 4

    Re: Help with boolean logic and constraints

    Terry Halpin:

    Like Clifford, I would typically use either two unaries, or one binary to a 3-valued type.

    For the unary approach, run a subset constraint from is-primary to is-active. In ORM (but not yet NORMA) you could capture the constraint that at most one class is primary by adding a role cardinality constraint of #<=1 to is-primary.

    For the binary approach, I would use the names active-primary, active-normal, and inactive. The restricted uniqueness constraint (active-primary applies to at most one class) would then have to be added manually as a textual constraint.

    Cheers

    Terry

    Thanks Terry. I was wondering why I couldn't do a role cardinality constraint in NORMA, thanks for that. I was referencing the brown book for this and that stood out to me as something I wanted to do and was looking for it in NORMA with no luck.

    Do I need to do something special for the unary approach? I thought I had tried it using the Subset Constraint but when clicking it added an extra role box and threw some errors. I double-clicked one role box, then double-clicked the other. I am still not sure what the difference totally is between single-click and double-click.

  • 10-28-2010 2:02 In reply to

    Re: Help with boolean logic and constraints

     To add the subset constraint, drag the subset constraint shape between the unaries, double-click it, then select the is-primary role and double-click it, then select the is-active-role and double-cilck it, then press Escape or double-click to to finish. With the cursor on the constraint shape, you should see 1.1 in the subset role and 2.1 in the superset role. Also the vrerbalization should appear as "If some Class is primary then that Class is active"

    Hope this helps

    Terry

Page 1 of 1 (6 items)
© 2008-2014 The ORM Foundation: A UK not-for-profit organisation -------------- Terms of Service