Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
67716dc3
Commit
67716dc3
authored
5 months ago
by
I. Nüske
Browse files
Options
Downloads
Patches
Plain Diff
DOC: Update filter tutorial
parent
1b3f81a8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!159
Release 0.16.o
,
!155
Review filter lists and compare_entities
Pipeline
#56992
passed with warnings
5 months ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/doc/tutorials/complex_data_models.rst
+22
-19
22 additions, 19 deletions
src/doc/tutorials/complex_data_models.rst
with
22 additions
and
19 deletions
src/doc/tutorials/complex_data_models.rst
+
22
−
19
View file @
67716dc3
...
...
@@ -91,39 +91,42 @@ entities. A short example:
r = db.Record()
p1 = db.Property(id=101, name="Property 1")
p2 = db.Property(id=102, name="Property 2")
p3 = db.Property(name="Property")
p3_1 = db.Property(id=103, name="Property 3")
p3_2 = db.Property(id=103, name="Property 3")
p4 = db.Property(name="Property")
r.add_property(p1).add_property(p2).add_property(p3).add_property(p4)
p5 = db.Property(name="Property")
r.add_property(p1).add_property(p2).add_property(p3_1)
r.add_property(p3_2).add_property(p4).add_property(p5)
properties = r.properties
# As r only has one property with id 101, this returns a list containing only p1
properties.filter(pid=101)
# Result: [p1]
# Filtering with name="Property" returns both p
3
and p
4
, as they share their name
# Filtering with name="Property" returns both p
4
and p
5
, as they share their name
properties.filter(name="Property")
# Result: [p
3
, p
4
]
# Result: [p
4
, p
5
]
# Filtering with name="Property 1" and id=102 returns both p1 and p2, because
# any property matching either criterion is returned:
properties.filter(name="Property 1", pid="102")
# Result: [p1, p2]
p6 = db.Property(name="Property 2")
r.add_property(p6)
# If we want to find properties matching one specific property, we can also filter using
# the entity itself. In this case, only properties matching both name and id are returned:
p5 = db.Property(name="Property 2")
r.add_property(p5)
properties.filter(p5)
# Result: [p5]
properties.filter(name=p5.name, pid=p5.id)
# Result: [p2, p5], because p2 and p5 share a name
properties.filter(p3)
# Result: [p3, p4], because p3 and p4 share both their name and id
# However, if you want to retrieve only instances of the property itself, this can be
# done using the parameter check_equality, which enforces that all entities in the returned
# list are equal to the parameter.
properties.filter(p3, check_equality=True)
# Result: [p3]
# the entity itself. In this case, only properties matching both name and id are returned,
# as long as both are set.
properties.filter(p2)
# Result: [p2]
# As p6 does not have an id yet, both candidates matching its name are returned
properties.filter(p6)
# Result: [p2, p6]
# Similarly if we match using name and id parameters, all candidates matching either are returned
properties.filter(name=p2.name, pid=p2.id)
# Result: [p2, p6], because p2 and p6 share a name
# And if both name and id match, there may also be several results when matching an entity
properties.filter(p3_1)
# Result: [p3_1, p3_2], because they share both their name and id
The filter function of ParentList works analogously.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment