I am getting a "too many inputs" error when trying to cascade delete tables

alias_index = cellfun(...
@(ref_attr, attr) ~strcmp(ref_attr, attr), ...
fks.ref_attrs, fks.attrs, 'uni', true);
Error ID:
---------
'MATLAB:TooManyInputs'
--------------
Error Details:
--------------
Error using dj.Relvar>@(ref_attr,attr)~strcmp(ref_attr,attr)
Too many input arguments.
Error in dj.Relvar/del (line 101)
alias_index = cellfun(...
Error in TestCasDel/TestCasDel_testCasDelete (line 30)
del(TestLab.User & key)

3 Comments

Hi, Carlos,
Your syntax seems right. What is the value of fks.ref_attrs and fks.attrs? They are supposed to be cell array.
Thanks,
Lei
Yes that is correct! they are cell arrays. Could you explain how the cellfun() method works with the ...@(x, y) and ~strcmp(x, y) function parameters?
"Could you explain how the cellfun() method works with the ...@(x, y) and ~strcmp(x, y) function parameters?"
Those are not separate parameters, that is an anonymous function provided as the first argument:
The error in your question is most likely caused by this:

Sign in to comment.

Answers (1)

fks is a non-scalar struct so struct expansion is occurring.

4 Comments

What would the fix be? I'm not sure how to address this.
@Carlos Ortiz : please upload fks in a .mat file by clicking the paperclip button.
Possibly
alias_index = cellfun(...
@(ref_attr, attr) ~strcmp(ref_attr, attr), ...
{fks.ref_attrs}, {fks.attrs}, 'uni', true);
but it would not astonish me if ismember() needed to be used instead of strcmp()
We tried this solution and it takes care of most cases but it doesn't take into account the FK being in the second column. Sorry if that explanation doesn't suffice. Kind of new to MatLab.
alias_index = cellfun(@(ref_attr, attr) ~strcmp(ref_attr, attr), fks(1).ref_attrs, fks(1).attrs, 'uni', true);
And here are the test cases that I'm working with...
users = [{'user0'; 'user1'; 'user2'}];
insert(TestLab.User, users);
duty = [{'2020-01-01','user0','user1'},
{'2020-12-31','user1','user2'}];
insert(TestLab.Duty, duty);
key.user_id = 'user2';
del(TestLab.User & key);
testCase.verifyEqual(length(fetch(TestLab.User & 'user_id != "user2"')), 2);
testCase.verifyEqual(length(fetch(TestLab.Duty & 'duty_second != "user2"')), 1);
Is there someway to make sure the cellfun() function can use both values?

Sign in to comment.

Asked:

on 11 Feb 2022

Commented:

on 21 Feb 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!