datajoint / datajoint-matlab

Relational data pipelines for the science lab
MIT License
42 stars 38 forks source link

Update foreign key definition syntax to match newer convention #350

Open guzman-raphael opened 3 years ago

guzman-raphael commented 3 years ago

Feature Request

Problem

Foreign key definition does not match newer syntax implemented in datajoint-python.

Currently it observes:

(new_attr1, new_attr2) -> [nullable, unique] ClassName.TableName(old_attr1, old_attr2)

Expected to accept:

-> [nullable, unique] ClassName.TableName.proj('old_attr1->new_attr1', 'old_attr2->new_attr2')

Requirements

Ensure the above expected syntax is respected.

Justification

Feature parity with datajoint-python.

gyellen commented 3 years ago

The python syntax is (according to the documentation) -> Table.project(new_attr='old_attr') so I'm assuming that the analogous syntax in MATLAB is -> [nullable, unique] ClassName.TableName.proj(new_attr1='old_attr1', new_attr2='old_attr2')

This matches the current Python syntax for sql math (as in the autoincrement example for primary keys) next='max(scan_idx)+1' though the syntax in Raphael's comment above better matches the current working syntax for autoincrement in MATLAB: key.scan_idx = fetch1(Scan & key, 'max(scan_idx)+1 -> next')

The table definition syntax is more flexible than the syntax for executable MATLAB code, because it is interpreted by the DJ Toolbox parser (from the block comment) rather than the MATLAB language parser. So the new='old' format can work in the table definition in MATLAB, but the next='max(scan_idx)+1' will not work in executable code.

Probably worth a discussion before the individual cases get handled differently...