mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-20 15:42:11 -04:00
30ee4263c0
<!-- Provide a general summary of your proposed changes in the Title field above --> ### Description <!-- Describe your changes in detail --> Remove print statements ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> This pull request is: - [X] A documentation / typographical error fix - Good to go, no issue or tests are needed - [ ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. **Have a nice day!** Closes: #5166 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5166 Pull-request-sha:04a7394f71Change-Id: Ib90a59fac929661a18748c6e44966fb87e3978c6 (cherry picked from commita836e3df5d)
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
"""
|
|
Illustrates "vertical table" mappings.
|
|
|
|
A "vertical table" refers to a technique where individual attributes
|
|
of an object are stored as distinct rows in a table. The "vertical
|
|
table" technique is used to persist objects which can have a varied
|
|
set of attributes, at the expense of simple query control and brevity.
|
|
It is commonly found in content/document management systems in order
|
|
to represent user-created structures flexibly.
|
|
|
|
Two variants on the approach are given. In the second, each row
|
|
references a "datatype" which contains information about the type of
|
|
information stored in the attribute, such as integer, string, or date.
|
|
|
|
|
|
Example::
|
|
|
|
shrew = Animal(u'shrew')
|
|
shrew[u'cuteness'] = 5
|
|
shrew[u'weasel-like'] = False
|
|
shrew[u'poisonous'] = True
|
|
|
|
session.add(shrew)
|
|
session.flush()
|
|
|
|
q = (session.query(Animal).
|
|
filter(Animal.facts.any(
|
|
and_(AnimalFact.key == u'weasel-like',
|
|
AnimalFact.value == True))))
|
|
print('weasel-like animals', q.all())
|
|
|
|
.. autosource::
|
|
|
|
"""
|