Associations
plateforme.core.associations
This module provides utilities to represent and manage associations between resources in the Plateforme framework.
Association
Association(*links: ResourceFieldInfo)
Bases: Representation
Represents the association between two resources.
This class is used to define how two resources are linked to each other, typically in a database or a similar structured data format. It captures the definition of the association, including its alias, the linked fields, and, if applicable, the association table for many-to-many associations.
Attributes:
Name | Type | Description |
---|---|---|
alias |
The alias name of the association. It must adhere to a specific
|
|
links |
A tuple containing one or two linked resource fields instances.
These linked fields define the association, they are sorted based
on three criteria:
- |
|
packages |
A set containing the |
|
table |
Table | None
|
The SQLAlchemy |
Initialize the association.
It creates an association of one or two linked fields using either the
association_alias
attribute if specified or by joining with an
underscore the sorted linked fields by their owner resource fully
qualified name. The association is added to their relative package
objects dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
links
|
ResourceFieldInfo
|
The linked resource fields that define the association. |
()
|
Note
For scenarios where an association table is required, the sorted first linked field package is considered the "owner" of the association, i.e. the table is created within the package metadata of the first linked field. This is a design choice to ensure a consistent and predictable order of linked fields and their implementation in the database.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/associations.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
build
Build the association between resources.
This process handles all types of associations such as many-to-unknown, many-to-many, one-to-unknown, one-to-many, many-to-one, and one-to-one. It performs the necessary logic to establish these associations, which may involve creating an association tables, foreign key columns, and validating resource indexes and association configurations.
Note
This method is an internal function and should not be called directly outside of class context.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/associations.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
plateforme.core.catalogs
This module provides utilities for managing catalogs of resources along with their associations, and services used within the Plateforme framework.
CatalogObject
module-attribute
CatalogObject: TypeAlias = (
"ResourceType | Association | Callable[..., Any]"
)
A type alias for an alias object that can be either a resource type, an association, or a service method.
WeakCatalogMap
module-attribute
WeakCatalogMap = WeakValueDictionary[str, CatalogObject]
A weak dictionary mapping an alias or a slug key to the object, either a resource type, an association, or a service method within a catalog.
WeakCatalogSet
module-attribute
WeakCatalogSet = WeakSet[CatalogObject]
A weak set of objects, either a resource type, an association, or a service method within a catalog.
Catalog
Catalog(owner: Any)
Bases: Iterable[CatalogObject]
A catalog of resources, associations, and services.
Attributes:
Name | Type | Description |
---|---|---|
owner |
The owner of the catalog. |
|
objects |
WeakCatalogSet
|
A weak set of objects, either a resource type, an association, or a service method within the catalog. |
aliases |
WeakCatalogMap
|
A weak dictionary mapping an alias key to the object instance, either a resource type, an association, or a service method within the catalog. |
slugs |
WeakCatalogMap
|
A weak dictionary mapping a slug key to the object instance, either a resource type, an association, or a service method within the catalog. |
Initialize the catalog.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owner
|
Any
|
The owner of the catalog. |
required |