Skip to content

Commit

Permalink
fix conditions on Compositions : 2nd multiplicity can be 0..n _or_ 0..1
Browse files Browse the repository at this point in the history
  • Loading branch information
damil committed Apr 25, 2024
1 parent ffed723 commit 1288702
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
1 change: 0 additions & 1 deletion lib/DBIx/DataModel/Doc/Quickstart.pod
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ we will introduce the new concept of I<composition>.
[qw/Activity activities * /]);

This looks exactly like an association declaration; but it states that

an activity somehow "belongs" to an employee (cannot exist without
being attached to an employee). In a UML class diagram, this would be
pictured with a black diamond on the Employee side. In this
Expand Down
2 changes: 1 addition & 1 deletion lib/DBIx/DataModel/Doc/Reference.pod
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ of kind C<Composition> is :

=item *

the multiplicity must be 1-to-n
the multiplicity must be 1-to-n or 1-to-0..1

=item *

Expand Down
6 changes: 3 additions & 3 deletions lib/DBIx/DataModel/Meta/Association.pm
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ sub _check_composition {
# multiplicities must be 1-to-n
$self->{A}{multiplicity}[1] == 1
or croak "max multiplicity of first class in a composition must be 1";
$self->{B}{multiplicity}[1] > 1
or croak "max multiplicity of second class in a composition must be > 1";
$self->{B}{multiplicity}[0] == 0
or croak "min multiplicity of second class in a composition must be 0";

# check for conflicting compositions
while (my ($name, $path) = each %{$self->{B}{table}{path} || {}}) {
Expand Down Expand Up @@ -402,7 +402,7 @@ Special behaviour is attached to the kind C<Composition> :
=item *
the multiplicity must be 1-to-n
the multiplicity must be 1-to-n or 1-to-0..1
=item *
Expand Down
2 changes: 1 addition & 1 deletion lib/DBIx/DataModel/Meta/Path.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sub new {

# if this is a composition path, remember it in the 'components' array
push @{$self->{from}{components}}, $path
if $self->{association}{kind} eq 'Composition' && $self->{multiplicity}[1] > 1;
if $self->{association}{kind} eq 'Composition' && $self->{multiplicity}[0] == 0;

# install a navigation method into the 'from' table class
my @navigation_args = ($self->{name}, # method name
Expand Down

0 comments on commit 1288702

Please sign in to comment.