Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
plugin_dbui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab has been updated. More info
here
and
there
.
Show more breadcrumbs
w2pext
plugin_dbui
Commits
2ac2159a
Commit
2ac2159a
authored
14 years ago
by
Renaud Le Gac
Browse files
Options
Downloads
Patches
Plain Diff
Add a method to build the query to resolve foreign key.
parent
705f25c4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/plugin_dbui/foreignfield.py
+32
-5
32 additions, 5 deletions
modules/plugin_dbui/foreignfield.py
with
32 additions
and
5 deletions
modules/plugin_dbui/foreignfield.py
+
32
−
5
View file @
2ac2159a
...
@@ -14,11 +14,13 @@ K_KEY = "k_key"
...
@@ -14,11 +14,13 @@ K_KEY = "k_key"
class
ForeignField
(
dict
):
class
ForeignField
(
dict
):
def
__init__
(
self
,
db
):
def
__init__
(
self
,
db
):
"""
Scan the database model to identify foreign key,
"""
Scan the database model to identify foreign key,
S
tore the p
ointing table and field
.
and to s
tore the p
arent table, field and key
.
"""
"""
self
.
_db
=
db
for
table
in
db
.
tables
:
for
table
in
db
.
tables
:
fields
=
[
db
[
table
][
el
]
for
el
in
db
[
table
].
fields
]
fields
=
[
db
[
table
][
el
]
for
el
in
db
[
table
].
fields
]
...
@@ -50,7 +52,7 @@ class ForeignField(dict):
...
@@ -50,7 +52,7 @@ class ForeignField(dict):
def
is_foreign_field
(
self
,
table
,
field
):
def
is_foreign_field
(
self
,
table
,
field
):
"""
Return true is the table.field is a foreign key.
"""
Return true is the table.field is a foreign key.
"""
"""
if
table
in
self
:
if
table
in
self
:
...
@@ -65,8 +67,8 @@ class ForeignField(dict):
...
@@ -65,8 +67,8 @@ class ForeignField(dict):
def
get_foreign_data
(
self
,
table
,
field
):
def
get_foreign_data
(
self
,
table
,
field
):
"""
Return a tuple containing the p
ointing
table, the p
ointing
field
"""
Return a tuple containing the p
arent
table, the p
arent
field
and
key
for the join:
and
primary key of the parent table
for the join:
table.field --> k_table.k_field
table.field --> k_table.k_field
table.field == k_table.k_key
table.field == k_table.k_key
...
@@ -80,3 +82,28 @@ class ForeignField(dict):
...
@@ -80,3 +82,28 @@ class ForeignField(dict):
else
:
else
:
return
None
return
None
def
get_where_query
(
self
,
table
):
"""
Return the query in order to handle foreign table.
Return None is there is no foreign keys.
"""
if
not
self
.
is_table_with_foreign_fields
(
table
):
return
None
db
,
query
=
self
.
_db
,
None
for
field
in
self
[
table
]:
k_table
=
self
[
table
][
field
][
K_TABLE
]
k_key
=
self
[
table
][
field
][
K_KEY
]
condition
=
db
[
table
][
field
]
==
db
[
k_table
][
k_key
]
if
query
:
query
=
((
query
)
&
(
condition
))
else
:
query
=
condition
return
query
\ No newline at end of file
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