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
Merge requests
!157
compare entities and parent/property lists
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
compare entities and parent/property lists
f-review-lists-and-compare
into
dev
Overview
1
Commits
25
Pipelines
7
Changes
8
1 unresolved thread
Hide all comments
Merged
Henrik tom Wörden
requested to merge
f-review-lists-and-compare
into
dev
5 months ago
Overview
1
Commits
25
Pipelines
7
Changes
5
1 unresolved thread
Hide all comments
Expand
redo
!155 (diffs)
0
0
Merge request reports
Compare
version 5
version 7
b2b5a8bd
5 months ago
version 6
d006797d
5 months ago
version 5
3997bcf9
5 months ago
version 4
bd17a251
5 months ago
version 3
68b48f76
5 months ago
version 2
3029b906
5 months ago
version 1
3029b906
5 months ago
dev (base)
and
latest version
latest version
5ad9e7fc
25 commits,
5 months ago
version 7
b2b5a8bd
18 commits,
5 months ago
version 6
d006797d
7 commits,
5 months ago
version 5
3997bcf9
6 commits,
5 months ago
version 4
bd17a251
5 commits,
5 months ago
version 3
68b48f76
3 commits,
5 months ago
version 2
3029b906
2 commits,
5 months ago
version 1
3029b906
42 commits,
5 months ago
Show latest version
5 files
+
357
−
230
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
src/doc/tutorials/complex_data_models.rst
+
36
−
40
Options
@@ -51,18 +51,18 @@ Examples
# Very complex part of the data model:
# Case 1: File added to another file
f2.add_property(p1, value=f1) # this adds a file property with value first file
# to the second file
# to the second file
# Case 2: Property added to a property
p2.add_property(p3, value=27) # this adds an integer property with value 27 to the
# double property
# double property
# Case 3: Reference property added to a property
# The property p2 now has two sub properties, one is pointing to
# record p2 which itself has the property p2, therefore this can be
# considered a loop in the data model.
p2.add_property(p4, value=r2) # this adds a reference property pointing to
# record 2 to the double property
# record 2 to the double property
# Insert a container containing all the newly created entities:
c = db.Container().extend([rt1, rt2, r1, r2, f1, p1, p2, p3, f2, p4])
@@ -87,46 +87,42 @@ entities. A short example:
import linkahead as db
# Setup a record with
four
properties
# Setup a record with
six
properties
r = db.Record()
p1 = db.Property(id=101, name="Property 1")
p2 = db.Property(
id=102,
name="Property
2
")
p
3
_1 = db.Property(id=10
3
, name="Property
3
")
p
3
_2 = db.Property(id=10
3, name="Property 3"
)
p
4
= db.Property(
name="
Property")
p
5
= db.Property(
name="
Property")
r.add_property(p1).add_property(p2).add_property(p
3
_1)
r.add_property(p
3
_2).add_property(p
4
).add_property(p
5
)
p1
_1
= db.Property(id=101, name="Property 1")
p
1_
2 = db.Property(name="Property
1
")
p
2
_1 = db.Property(id=10
2
, name="Property
2
")
p
2
_2 = db.Property(id=10
2
)
p
2_3
= db.Property(
id=102, name="Other
Property")
p
3
= db.Property(
id=104, name="Other
Property")
r.add_property(p1
_1
).add_property(p
1_
2).add_property(p
2
_1)
r.add_property(p
2
_2).add_property(p
2_3
).add_property(p
3
)
properties = r.properties
# As r only has one property with id 101, this returns a list containing only p1
# As r only has one property with id 101, this returns a list containing only p1
_1
properties.filter(pid=101)
# Result: [p1]
# Filtering with name="Property" returns both p4 and p5, as they share their name
properties.filter(name="Property")
# Result: [p4, p5]
# 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,
# 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
# Result: [p1_1]
# Filtering with name="Property 1" returns both p1_1 and p1_2, as they share their name
properties.filter(name="Property 1")
# Result: [p1_1, p1_2]
# If both name and pid are given, matching is based only on pid for all entities that have an id
properties.filter(pid="102", name="Other Property")
# Result: [p2_1, p2_2, p2_3]
# However, filtering with name="Property 1" and id=101 returns both p1_1 and p1_2, because
# p1_2 does not have an id and matches the name
properties.filter(pid="101", name="Property 1")
# Result: [p1_1, p1_2]
# We can also filter using an entity, in which case the name and id of the entity are used:
properties.filter(pid="102", name="Property 2") == properties.filter(p2_1)
# Result: True
# If we only need properties that match both id and name, we can set the parameter
# conjunction to True:
properties.filter(pid="102", name="Property 2", conjunction=True)
# Result: [p2_1]
The filter function of ParentList works analogously.
Loading