Fact problem

R

Rickard Axne

I'm trying to get my ORM facts right for modelling a Project:

* Project(Id) is Approved() by Employee(Id) on Date()

Approved E ('Y', 'N')

I understand n-ary facts must have uniquness on n-1 predicates? But I
want the approval to be either unset, yes or no.

Anyway I am struggling to get this right. Also tried with a nested fact,
but it doesn't allow me to set only the Project unique, only both
Project and Approved()

Any idea welcome. I think I want something along these lines in terms of
DDL:

Project(ProjectId PK, , , ...)
ApprovedProject(ProjectID PK, ApprovalStatus, ApprovalDate, ApprovedByEmpId)

TIA
 
S

Scot Becker

Hi Rickard,
I'm trying to get my ORM facts right for modelling a Project:

* Project(Id) is Approved() by Employee(Id) on Date()

Approved E ('Y', 'N')

I understand n-ary facts must have uniquness on n-1 predicates? But I
want the approval to be either unset, yes or no.

Anyway I am struggling to get this right. Also tried with a nested fact,
but it doesn't allow me to set only the Project unique, only both
Project and Approved()

Any idea welcome. I think I want something along these lines in terms of
DDL:

Project(ProjectId PK, , , ...)
ApprovedProject(ProjectID PK, ApprovalStatus, ApprovalDate,
ApprovedByEmpId)

It doesn't sound like your fact is elementary; A violation of the n-1 rule
and/or a desire to have only one role of a nested fact type be unique are
often clues that this is the case

Is a project only approved once? If so, the facts would be (making some rule
assumptions):

Project(id) is approved on Date()
Project(id) is approved by Employee(id)
Project(id) has Approval Type(code)

All facts have a UC over the Project role, and the Project role is
mandatory, and Approval Role can be one of three values (e.g. Y, N, U)

If a Project can be approved multiple times, the facts might be (again,
making some rule assumptions)::

1) Project(id) is approved on Date()
This fact is nested as "Approval"
A UC spans both roles

2) Approval has Approval Type(code)
Approval role has a UC
Approval role is mandatory
Approval Type has Values of "Y", "N", "U" (or whatever code you want, but it
has 3 states)

3) Approval is entered by Employee(id)
Approval role has a UC
Approval role is mandatory

You could have the Approval Type fact be optional in both of these cases. If
so, then only allow two values (e.g. Y, N) and leave un-entered to mean
unknown. However, I generally prefer to have unknown be explicitly coded as
above.

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.
 
R

Rickard Axne

Scot said:
It doesn't sound like your fact is elementary; A violation of the n-1 rule
and/or a desire to have only one role of a nested fact type be unique are
often clues that this is the case

Thanks Scott,

I guess this is where I have a slight problem with ORM; i don't fully
understand when a fact is elemtary or not. Why is

Student(Id) took Course(Code) which resulted in Grade()

...elementary (I think Halpin uses this example or something similar in
his book) whereas ..

Project was Approved(Code) on Date() by Employee(Id)

is not?

Halpin is not very clear on this in his book. Allthough I like the book
overall, I wish in the next verison, he puts more effort on the
complicated stuff instead of how to make reports etc.

Thanks
 
R

Rickard Axne

Scot Becker wrote:

Is a project only approved once? If so, the facts would be (making some rule
assumptions):

Project(id) is approved on Date()
Project(id) is approved by Employee(id)
Project(id) has Approval Type(code)

All facts have a UC over the Project role, and the Project role is
mandatory, and Approval Role can be one of three values (e.g. Y, N, U)

Hi again Scott,

I tried this and generating a logical schema. As I suspected, these
rules maps to one column each in my Project table. I want to avoid
colums that depend on anything else rather than the PK as much as
possible. Therefore, I think what I want is something like this:

Project (ProjId PK, ProjName, ....)
ApprovedProject (ProjId PK FK, Status, Date, ApprovedByEmpId)

This allows me to create easy constraints to protect data integrity
within ApprovedProjects.

Allthough I like your idea with U etc for unset status in general, for
this specific instance, I dont want the user to *actively* be able to
set it to Unset <g> and I want to check this with the abscence of
ApprovedProject.

Yes, there can only be one approval (Y/N) in ApprovedProject, therefore
the PK on ProjId.

Am I violating any design rule here? Because otherwise it seems strange
that ORM doesn't allow me to make it generate this logical design.

Any input appriciated. Perhaps I should take this to c.db.theroy?

Thanks Scott,

Rickard
 
S

Scot Becker

Hi Rickard,
I guess this is where I have a slight problem with ORM; i don't fully
understand when a fact is elemtary or not. Why is

Student(Id) took Course(Code) which resulted in Grade()

..elementary (I think Halpin uses this example or something similar in
his book) whereas ..

Project was Approved(Code) on Date() by Employee(Id)

is not?

The short answer has to do with functional dependencies. Approved, Date, and
Employee are functionally dependant on Project and Project alone. In the
course example, the grade is related to a Student AND a Course.
Halpin is not very clear on this in his book. Allthough I like the book
overall, I wish in the next verison, he puts more effort on the
complicated stuff instead of how to make reports etc.

When you say "book" are you talking about Information Modeling and
Relational Databases or the Database Modeling with Visio one? The former
details the ORM method, the latter has to do with the tool itself (and
minimal instruction on how to actually do ORM). If you are new to ORM, I
definitely think you should pick up the first one. Terry's website,
www.orm.net, also has some whitepapers that might interest you.

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.
 
S

Scot Becker

Hi Rickard,
I tried this and generating a logical schema. As I suspected, these
rules maps to one column each in my Project table. I want to avoid

By default, the mapping algorithm will avoid making arbitrary one-to-one
related tables.
colums that depend on anything else rather than the PK as much as
possible. Therefore, I think what I want is something like this:

Project (ProjId PK, ProjName, ....)
ApprovedProject (ProjId PK FK, Status, Date, ApprovedByEmpId)

This allows me to create easy constraints to protect data integrity
within ApprovedProjects.

Ah... You want to use subtypes then. The facts remain pretty much as I
listed them before, but you now introduce 1 to 3 new objects (e.g.
ApprovedProject, RejectedProject, and maybe UnknownProject) that are
subtypes of Project. You can then have facts and constraints distinct for
each (e.g. RejectedProject has RejectReason() ) but keep those common to all
(Approval Code, Date of Approval Code, etc.) at the project level. Then,
there is a mapping option you can set that will create separate tables for
each subtype with a one-to-one inheritance relationship with the Project
Table.

You'll use the subtype arrow for this; the arrow points from the child (e.g.
Approved Project) to the parent (Project).
Allthough I like your idea with U etc for unset status in general, for
this specific instance, I dont want the user to *actively* be able to
set it to Unset <g> and I want to check this with the abscence of
ApprovedProject.

You could do it either way then. Regardless of your decision, you will have
some logic built in somewhere that would make sure it is not null or not U
for certain states. I generally try to avoid nulls (for lots of reasons).
Yes, there can only be one approval (Y/N) in ApprovedProject, therefore
the PK on ProjId.

I still think the Approval Code (Y, N, U) is a fact of Project and belongs
in the project table. I think introducing subtypes as above will alleviate
your concern about column and rule isolation for each type. Further, this
fact will guide the rule as to which child table is actually populated
(ApprovedProject is only populated for "Y", etc.) and as such is a fact
about all projects -- and belongs at the project level -- regardless of
status.
Am I violating any design rule here? Because otherwise it seems strange
that ORM doesn't allow me to make it generate this logical design.

No, ORM can do this as per the above. You could also do it the hard way by
introducing a one-to-one fact type for a brand new object which will more or
less do the above. Subtypes are a better (and conceptually cleaner) way to
handle this.
Any input appriciated. Perhaps I should take this to c.db.theroy?

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.
 
R

Rickard Axne

Scot said:
The short answer has to do with functional dependencies. Approved, Date, and
Employee are functionally dependant on Project and Project alone. In the
course example, the grade is related to a Student AND a Course.

Excellent, now I fully understand the meaning of elmentary facts.
When you say "book" are you talking about Information Modeling and
Relational Databases or the Database Modeling with Visio one? The former
details the ORM method, the latter has to do with the tool itself (and
minimal instruction on how to actually do ORM). If you are new to ORM, I
definitely think you should pick up the first one. Terry's website,
www.orm.net, also has some whitepapers that might interest you.

I thought I could get away with the Visio book along with various white
papers on Halpin's site, MSDN or any other google result. Your blog is
also very good, interesting topics.

Thanks for you effort Scott, great answers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top