Skip to content

Commit 7fe14f5

Browse files
authored
Merge pull request #377 from guzman-raphael/fetchn-join-issue
Add comments on foreign key logic
2 parents b9ec57b + f55af30 commit 7fe14f5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

+dj/Relvar.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,27 @@ function cleanup(self)
8787
self.schema.conn.tableToClass(child),list)), rels(i).children)
8888
% and restrict them by it or its restrictions
8989
if restrictByMe(i)
90+
% Extract foreign key indices for table that match target parent
9091
fk_index = arrayfun(...
9192
@(x) strcmp(x.from, rels(ix).fullTableName), ...
9293
self.schema.conn.foreignKeys, 'uni', true);
9394
fks = self.schema.conn.foreignKeys(fk_index);
9495
if ~fks.aliased
96+
% If matched foreign keys are not aliased, no renaming
97+
% necessary. Restrict table based on normal projection.
9598
rels(ix).restrict(proj(rels(i)));
9699
else
100+
% Determine which foreign keys have been renamed
97101
alias_index = cellfun(...
98102
@(ref_attr, attr) ~strcmp(ref_attr, attr), ...
99103
fks.ref_attrs, fks.attrs, 'uni', true);
104+
% Create rename arguments for projection
100105
aliased_attrs = cellfun(...
101106
@(ref_attr, attr) sprintf('%s->%s', ref_attr, attr), ...
102107
fks.ref_attrs(alias_index), fks.attrs(alias_index), ...
103108
'uni', false);
109+
% Restrict table based on projection with rename arguments on
110+
% foreign keys.
104111
rels(ix).restrict(proj(rels(i), aliased_attrs{:}));
105112
end
106113
else

0 commit comments

Comments
 (0)