Relations plugin for model builder
Relation data type
The relation data type marks part of the metadata that will be filled with a related object.
Example usage - part of dataset model:
primary-article:
type: relation
name: article
model: article
keys: ['metadata.title', 'metadata.authors']
The element "primary-article" will be connected to the article record. The record class and properties will be taken from the "article" model that is registered in "oarepo_models" entrypoint.
When returned to the user/serialized to ES, it will take the title and author fields from the related model and copy them into the primary-article field.
It will automatically generate the following schema:
will generate:
// schema
{
"primary-article": {
"type": "object",
"properties": {
"id": {"type": "string"},
"@v": {"type": "string"},
"title": {}, // copied from registered article model
"authors": {} // copied from registered article model
}
}
}
class Record:
# ...
relations = MultiRelationsField(
article=PIDRelation( # "name" from above
"...primary-article", # path inside the dataset model
"keys": ['metadata.title', 'metadata.authors'], # copied keys
pid_field: Article.pid # resolved model name and PID field
)
)
All arguments:
primary-article:
type: relation
name: ...
model: ...
keys: [...]
model-class:
relation-classes:
list: PIDListRelation
nested: PIDNestedListRelation
single: PIDRelation
relation-class:
relation-args:
attrs: []
keys: []
_value_key_suffix: id
_clear_empty: true
cache_key:
value_check:
pid_field: model-class.pid
imports:
- import: invenio_records_resources.records.system_fields.relations.PIDRelation
alias: PIDRelation
| Field | Description |
|---|---|
| name | Relation name, will be used as param name inside RelationsField |
| model | Name of the referenced model - from oarepo.models entrypoint or passed on commandline via --include parameter |
| keys | Array of paths or dicts. If item is a path, that path will be copied from the referenced model. If it is dict it must contain the whole model definition. |
| model-class | Class representing the related model |
| relation-classes | If the field is not an array and not nested inside an array, "single" is used. If the field is an array "list" is used. If the field is inside an array field, "nested" is used |
| relation-class | can be used to override relation-classes |
| relation-args | A dictionary of arguments that will be passes to the relation class |
| imports | You can define your own imports/aliases here. The defaults are thise for list, nested and single relation classes |
Internal relations
Sometimes it you might want to reference part of your document for indexing purposes etc. and not split the document into two records. For these, internal relations can be used:
properties:
metadata:
properties:
obj{}:
^id: anchor-obj
test: keyword
id: keyword
On object/array item, define the "id" field containing your "symbolic" name of the target of the relation. Then the definition of the relation will look like:
properties:
metadata:
properties:
internal-ref:
type: relation
model: "#anchor-obj"
keys: [id, test]
Supported relations
See referrer.yaml for a list of supported relations.
Metadata
Release files for oarepo-model-builder-relations 4.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| oarepo_model_builder_relations-4.0.11.tar.gz | 9.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| oarepo_model_builder_relations-4.0.11-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 25.5 kB
Release files / oarepo_model_builder_relations-4.0.11.tar.gz
| Download URL | oarepo_model_builder_relations-4.0.11.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad8eafeac9e8b8204ac0be97c3b5abbc168ef7f61ebf58d1a159e0bc5c36e23d
|
|
BLAKE2b-256 checksum How to use checksums |
c05601d2a31b5c62da4494b7bbcb850046c5e3326776ca60cb89f7515b8b5f98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / oarepo_model_builder_relations-4.0.11-py2.py3-none-any.whl
| Download URL | oarepo_model_builder_relations-4.0.11-py2.py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
930e651ba635c87dd37a828b21ad3ab1fe6ebd67f2c12982ff10f0f033d38601
|
|
BLAKE2b-256 checksum How to use checksums |
e76c850047abe7c93dc9ed059b3da6b50ebe7e0f70a26c6686648fd9ad275632
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|