Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
configdb
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
Service Desk
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ai
configdb
Commits
d0234c76
Commit
d0234c76
authored
12 years ago
by
joe
Browse files
Options
Downloads
Patches
Plain Diff
Fixing issue with two-way referenced relations in the sqlalchemy interface (closes issue #13)
parent
e5dc6836
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
configdb/db/interface/sa_generator.py
+16
-4
16 additions, 4 deletions
configdb/db/interface/sa_generator.py
configdb/db/interface/sa_interface.py
+2
-2
2 additions, 2 deletions
configdb/db/interface/sa_interface.py
with
18 additions
and
6 deletions
configdb/db/interface/sa_generator.py
+
16
−
4
View file @
d0234c76
...
@@ -8,6 +8,7 @@ class SqlAlchemyGenerator(object):
...
@@ -8,6 +8,7 @@ class SqlAlchemyGenerator(object):
def
__init__
(
self
,
schema_obj
):
def
__init__
(
self
,
schema_obj
):
self
.
schema
=
schema_obj
self
.
schema
=
schema_obj
self
.
defined_relations
=
[]
def
_audit_table_def
(
self
):
def
_audit_table_def
(
self
):
return
"""
return
"""
...
@@ -76,6 +77,13 @@ class %(class_name)s(Base):
...
@@ -76,6 +77,13 @@ class %(class_name)s(Base):
field
.
name
,
'
,
'
.
join
(
args
))
field
.
name
,
'
,
'
.
join
(
args
))
def
_sa_field_relation_def
(
self
,
entity
,
field
):
def
_sa_field_relation_def
(
self
,
entity
,
field
):
assoc_table
=
self
.
_sa_assoc_table_name
(
field
)
if
assoc_table
in
self
.
defined_relations
:
# In this case, we don't need a backref (it already exists)
return
'
%s = relationship(
"
%s
"
, secondary=%s)
'
%
(
field
.
name
,
field
.
remote_name
.
capitalize
(),
assoc_table
+
'
_table
'
)
return
'
%s = relationship(
"
%s
"
, secondary=%s, backref=
"
%s
"
)
'
%
(
return
'
%s = relationship(
"
%s
"
, secondary=%s, backref=
"
%s
"
)
'
%
(
field
.
name
,
field
.
name
,
field
.
remote_name
.
capitalize
(),
field
.
remote_name
.
capitalize
(),
...
@@ -83,12 +91,17 @@ class %(class_name)s(Base):
...
@@ -83,12 +91,17 @@ class %(class_name)s(Base):
pl
.
plural
(
entity
.
name
))
pl
.
plural
(
entity
.
name
))
def
_sa_field_assoc_table_def
(
self
,
entity
,
field
):
def
_sa_field_assoc_table_def
(
self
,
entity
,
field
):
table_name
=
self
.
_sa_assoc_table_name
(
field
)
if
table_name
in
self
.
defined_relations
:
#we have a 2-way used relation, and do not want to re-define it
return
""
self
.
defined_relations
.
append
(
table_name
)
return
"""
return
"""
%s_table = Table(
'
%s
'
, Base.metadata,
%s_table = Table(
'
%s
'
, Base.metadata,
Column(
'
left_id
'
, Integer, ForeignKey(
'
%s.id
'
)),
Column(
'
left_id
'
, Integer, ForeignKey(
'
%s.id
'
)),
Column(
'
right_id
'
, Integer, ForeignKey(
'
%s.id
'
)))
"""
%
(
Column(
'
right_id
'
, Integer, ForeignKey(
'
%s.id
'
)))
"""
%
(
self
.
_sa_assoc_
table_name
(
field
)
,
table_name
,
self
.
_sa_assoc_
table_name
(
field
)
,
table_name
,
field
.
local_name
,
field
.
local_name
,
field
.
remote_name
)
field
.
remote_name
)
...
@@ -106,4 +119,3 @@ class %(class_name)s(Base):
...
@@ -106,4 +119,3 @@ class %(class_name)s(Base):
out
.
append
(
self
.
_sa_entity_aux_tables
(
ent
))
out
.
append
(
self
.
_sa_entity_aux_tables
(
ent
))
out
.
append
(
self
.
_sa_entity_def
(
ent
))
out
.
append
(
self
.
_sa_entity_def
(
ent
))
return
'
\n
'
.
join
(
out
)
return
'
\n
'
.
join
(
out
)
This diff is collapsed.
Click to expand it.
configdb/db/interface/sa_interface.py
+
2
−
2
View file @
d0234c76
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