Hey Team -
So I'm working on a relatively fun hierarchy that allows me to relate tasks to games.
So I have 2 tables:
# A Generic Task Definition - not related to anything
class Task_Definition(Base):
def __repr__(self):
return (
"<TaskDefinition id='" + str(
self.id) + "' "
__table__ = task_definition_table # has name, id, etc...
# and a Task Table - specific to a game:
class Task(Base):
def __repr__(self):
return (
+ "' game_id='" + str(self.game_id)
+ " task_definition_id=" + str(self.task_definition_id) + "'>")
__table__ = task_table # has game_id, start_dttm, end_dttm, etc...
So originally I had my task as a
__table__ = join(task_definition_table, task_table)
That allowed me to select a task, and see all of the task_definition properties as one "Object"
But the problem is: when I created a task - it wanted to create a new task_definition at the same time, which is not what I wanted - given that task_definitions are a generic that can be used anytime.
So then I created a task like this:
class Task(Base):
def __repr__(self):
return (
+ "' game_id='" + str(self.game_id)
+ " task_definition_id=" + str(self.task_definition_id) + "'>")
__table__ = task_table
task_definition_id = column_property(
task_definition_language_table.c.task_definition_id,
task_table.c.task_definition_id)
description = column_property(task_definition_language_table.c.description)
instructions = column_property(
task_definition_language_table.c.instructions)
That allowed me to insert properly - but then my selects were coming back with tons of duplicate rows.
When I played with the query - it was because it was doing a
SELECT * from task, task_definition
as opposed to a
select * from task JOIN task_definition...
Is there an easy way to force a join on select, and then a direct table communication on insert?
-Mike