ValueObject field
Field descriptor for embedding value objects within aggregates or entities.
Bases: Field
Represents a field that holds a value object.
This field is used to embed a value object within an entity. It provides functionality to handle the value object's fields and their values.
| PARAMETER | DESCRIPTION |
|---|---|
value_object_cls
|
The class of the value object to be embedded.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
embedded_fields |
A dictionary that holds the embedded fields of the value object.
TYPE:
|
Source code in src/protean/fields/embedded.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
embedded_fields
cached
property
embedded_fields: dict[str, _ShadowField]
Property to retrieve embedded fields
get_shadow_fields
get_shadow_fields() -> list[
tuple[str | None, _ShadowField]
]
Return shadow field Primarily used during Entity initialization to register shadow field
Source code in src/protean/fields/embedded.py
174 175 176 177 178 179 180 | |
as_dict
as_dict(value: Any) -> Any
Return JSON-compatible value of self
Source code in src/protean/fields/embedded.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
__set__
__set__(instance: Any, value: Any) -> None
Override __set__ to coordinate between value object and its embedded fields
Source code in src/protean/fields/embedded.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
ValueObjectFromEntity field
Field descriptor that auto-generates a value object from an entity class.
Convenience wrapper over value_object_from_entity() for inline use in
commands and events.
Bases: ValueObject
Field descriptor that auto-generates a Value Object from an Entity class.
Thin convenience wrapper over value_object_from_entity() -- instead of
creating the VO class yourself, this descriptor derives it from the entity
at class-body evaluation time::
class PlaceOrder(BaseCommand):
items: List(content_type=ValueObjectFromEntity(OrderItem))
Source code in src/protean/fields/embedded.py
266 267 268 269 270 | |
value_object_from_entity
Utility function that creates a BaseValueObject subclass mirroring an
entity's fields. See the
Value Objects guide
for usage patterns.
Create a BaseValueObject subclass whose fields mirror entity_cls.
This eliminates the boilerplate of manually duplicating an entity's fields into a value object for use in commands and events.
| PARAMETER | DESCRIPTION |
|---|---|
entity_cls
|
The entity (or aggregate) class to project.
TYPE:
|
name
|
Override the generated class name (default:
TYPE:
|
exclude
|
Field names to omit from the generated value object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[BaseValueObject]
|
A new |
Source code in src/protean/core/value_object.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |