diff --git a/+dj/+internal/Header.m b/+dj/+internal/Header.m index 9de65169..e41a4999 100644 --- a/+dj/+internal/Header.m +++ b/+dj/+internal/Header.m @@ -152,25 +152,25 @@ function project(self, params) include = [self.attributes.iskey]; % always include the primary key for iAttr=1:length(params) - if strcmp('*',params{iAttr}) + if strcmp('*', params{iAttr}) include = include | true; % include all attributes else % process a renamed attribute toks = regexp(params{iAttr}, ... '^([a-z]\w*)\s*->\s*(\w+)', 'tokens'); if ~isempty(toks) - ix = find(strcmp(toks{1}{1},self.names)); + 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}); + 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}) + 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}) self.attributes(ix).name = toks{1}{2}; self.attributes(ix).alias = toks{1}{1}; else diff --git a/LNX-docker-compose.yaml b/LNX-docker-compose.yaml index 74d7781a..13c6e09b 100644 --- a/LNX-docker-compose.yaml +++ b/LNX-docker-compose.yaml @@ -29,7 +29,7 @@ services: interval: 1s fakeservices.datajoint.io: <<: *net - image: datajoint/nginx:v0.1.0 + image: datajoint/nginx:v0.1.1 environment: - ADD_db_TYPE=DATABASE - ADD_db_ENDPOINT=db:3306 diff --git a/local-docker-compose.yaml b/local-docker-compose.yaml index 3873bc49..da303d95 100644 --- a/local-docker-compose.yaml +++ b/local-docker-compose.yaml @@ -34,7 +34,7 @@ services: interval: 1s fakeservices.datajoint.io: <<: *net - image: datajoint/nginx:v0.1.0 + image: datajoint/nginx:v0.1.1 environment: - ADD_db_TYPE=DATABASE - ADD_db_ENDPOINT=db:3306 @@ -132,7 +132,6 @@ services: - /tmp/.X11-unix:/tmp/.X11-unix:rw ## Additional mounts may go here # - ./notebook:/home/muser/notebooks - # - ./matlab.prf:/tmp/matlab.prf networks: main: \ No newline at end of file diff --git a/tests/TestDelete.m b/tests/TestDelete.m index e8dd920c..66fb93eb 100644 --- a/tests/TestDelete.m +++ b/tests/TestDelete.m @@ -59,8 +59,10 @@ function TestDelete_testTwoFKOnePK(testCase) key.user_id = 'user1'; del(TestLab.User & key); - testCase.verifyEqual(length(fetch(TestLab.User & 'user_id != "user1"')), 2); - testCase.verifyEqual(length(fetch(TestLab.Duty & 'duty_second != "user1"')), 1); + testCase.verifyEqual(length(fetch(TestLab.User)), 2); + testCase.verifyEqual(length(fetch(TestLab.Duty)), 1); + testCase.verifyEqual(length(fetch(TestLab.User & 'user_id = "user1"')), 0); + testCase.verifyEqual(length(fetch(TestLab.Duty & 'duty_first = "user1" OR duty_second = "user1"')), 0); end end end \ No newline at end of file diff --git a/tests/TestProjection.m b/tests/TestProjection.m index 55db3a6e..1a067f1d 100644 --- a/tests/TestProjection.m +++ b/tests/TestProjection.m @@ -25,6 +25,34 @@ function TestProjection_testDateConversion(testCase) res = q.fetch1('enrolled_date'); testCase.verifyEqual(res, '2018-01-24'); + + dj.config('safemode', 0); + drop(University.Student); + end + function TestProjection_testRenameSameKey(testCase) + st = dbstack; + disp(['---------------' st(1).name '---------------']); + package = 'University'; + + c1 = dj.conn(... + testCase.CONN_INFO.host,... + testCase.CONN_INFO.user,... + testCase.CONN_INFO.password,'',true); + + dj.createSchema(package,[testCase.test_root '/test_schemas'], ... + [testCase.PREFIX '_university']); + + insert(University.Student, { + 10 'Raphael' 'Guzman' datestr(datetime, 'yyyy-mm-dd HH:MM:SS') + 11 'Shan' 'Shen' '2019-11-25 12:34:56' + 12 'Joe' 'Schmoe' '2018-01-24 14:34:16' + }); + + q = proj(University.Student & 'first_name = "Raphael"', 'student_id->faculty_id', 'student_id->school_id'); + testCase.verifyEqual(q.fetch('faculty_id', 'school_id'), struct('faculty_id', 10, 'school_id', 10)); + + dj.config('safemode', 0); + drop(University.Student); end end end \ No newline at end of file