Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: RelationalBone add getDefaultValue #1172

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/viur/core/bones/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,27 @@ def getUniquePropertyIndexValues(self, valuesCache: dict, name: str) -> list[str
elif isinstance(value, list):
return self._hashValueForUniquePropertyIndex([x["dest"]["key"] for x in value])

def getDefaultValue(self, skeletonInstance):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about multilang?

if callable(self.defaultValue):
key = self.defaultValue(skeletonInstance, self)
elif isinstance(self.defaultValue, list):
key = self.defaultValue
elif isinstance(self.defaultValue, dict):
return self.defaultValue.copy()
else:
key = self.defaultValue
if not key:
return None
if self.multiple:
if isinstance(key, list):
return [self.createRelSkelFromKey(k) for k in key]
else:
return [self.createRelSkelFromKey(key)]
else:
if isinstance(key, list):
key = key[0]
return self.createRelSkelFromKey(key)

def structure(self) -> dict:
return super().structure() | {
"type": f"{self.type}.{self.kind}",
Expand Down
Loading