Mixing defaults, references inside a record #2188
-
My goal is to find a way to create simple records with sane defaults. An example of what I would like to do in nixel is to use a schema (Link here) such that:
which would generate the following record "link1": {
"path_type": "file",
"source": { "file": "file_src_nondefault.csv", "folder": "folder_src_nondefault" },
"target": { "file": "file_tgt_nondefault.csv", "folder": "folder_tgt_nondefault" }
} but also allow for by default giving me file in target which comes from source
and the record (note that the file in target is source.file) "link1": {
"path_type": "file",
"source": { "file": "file_src_nondefault.csv", "folder": "folder_src_nondefault" },
"target": { "file": "file_src_nondefault.csv", "folder": "folder_tgt_nondefault" }
} I have created some contract -- note the function that tries to fet the source.file value inside of target as a default:
I find that when I create a record that has some elements in I am totally new to this. Sorry if the question is trivial, but I could not figure it out from the documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
I can explain the merge behavior that you're seeing: when you merge two records that have the same field, if one of the records has a higher merge priority on that field then it "wins", and if they have the same merge priority then the values of the fields are merged recursively. For example,
outputs {
"subfield1": {
"bar": 1
},
"subfield2": {
"bar": 1,
"foo": 1
}
} The "subfield1" values aren't merged recursively because the "default" one just loses outright. My other feedback is that for fields that are themselves records, it's often better to define subcontracts using "|" than to set values using "=". There a manual section about this. So I might try something like
The |
Beta Was this translation helpful? Give feedback.
I can explain the merge behavior that you're seeing: when you merge two records that have the same field, if one of the records has a higher merge priority on that field then it "wins", and if they have the same merge priority then the values of the fields are merged recursively. For example,
outputs
The "subfield1" values aren't merged recursively because the "default" one just loses outright.
My other feedback is that for fields that are themselves records, it's of…