Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions +dj/+internal/Header.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ function project(self, params)
'^([a-z]\w*)\s*->\s*(\w+)', 'tokens');
if ~isempty(toks)
ix = find(strcmp(toks{1}{1},self.names));
if ~length(ix)
ix = find(strcmp(toks{1}{1},{self.attributes.alias}));
assert(length(ix)==1,'Attribute `%s` not found',toks{1}{1});
self.attributes(self.count + 1) = self.attributes(ix);
self.attributes(self.count).name = self.attributes(self.count).alias;
self.attributes(self.count).alias = '';
ix = self.count;
end
assert(length(ix)==1,'Attribute `%s` not found',toks{1}{1});
assert(~ismember(toks{1}{2},union({self.attributes.alias}, ...
self.names)), 'Duplicate attribute alias `%s`',toks{1}{2})
Expand Down
17 changes: 8 additions & 9 deletions +dj/Relvar.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,16 @@ function cleanup(self)
rels(ix).restrict(proj(rels(i)));
else
% Determine which foreign keys have been renamed
alias_index = cellfun(...
@(ref_attr, attr) ~strcmp(ref_attr, attr), ...
fks(1).ref_attrs, fks(1).attrs, 'uni', true);
% Create rename arguments for projection
aliased_attrs = cellfun(...
@(ref_attr, attr) sprintf('%s->%s', ref_attr, attr), ...
fks(1).ref_attrs(alias_index), fks(1).attrs(alias_index), ...
'uni', false);
fks_ref_attrs_flattened = arrayfun(@(x) x.ref_attrs{:}, fks, 'UniformOutput', false);
fks_attrs_flattened = arrayfun(@(x) x.attrs{:}, fks, 'UniformOutput', false);
% Build OR string query using original and renamed attributes
or_string_query = strjoin(cellfun(...
@(attr,ref_attr) sprintf('%s = "%s"', attr, rels(i).fetch1(ref_attr)), ...
fks_attrs_flattened, fks_ref_attrs_flattened, ...
'uni', 0), ' OR ');
% Restrict table based on projection with rename arguments on
% foreign keys.
rels(ix).restrict(proj(rels(i), aliased_attrs{:}));
rels(ix).restrict(or_string_query);
end
else
rels(ix).restrict(rels(i).restrictions{:});
Expand Down
2 changes: 1 addition & 1 deletion local-docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ services:
ports:
- "8888:8888"
user: ${MATLAB_UID}:${MATLAB_GID}
working_dir: /home/muser/notebooks
working_dir: /home/muser
command:
- /bin/bash
- -c
Expand Down
9 changes: 5 additions & 4 deletions tests/TestDelete.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ function TestDelete_testTwoFKOnePK(testCase)
insert(TestLab.User, users);

duty = [{'2020-01-01','user0','user1'},
{'2020-12-31','user1','user2'}];
{'2020-01-02','user1','user2'},
{'2020-12-31','user0','user2'}];

insert(TestLab.Duty, duty);

key.user_id = 'user2';
key.user_id = 'user1';
del(TestLab.User & key);

testCase.verifyEqual(length(fetch(TestLab.User & 'user_id != "user2"')), 2);
testCase.verifyEqual(length(fetch(TestLab.Duty & 'duty_second != "user2"')), 1);
testCase.verifyEqual(length(fetch(TestLab.User & 'user_id != "user1"')), 2);
testCase.verifyEqual(length(fetch(TestLab.Duty & 'duty_second != "user1"')), 1);
end
end
end