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) + "' "
            + "name='" + self.name + "'>")
    __table__ = task_definition_table # has name, id, etc...

# and a Task Table - specific to a game:
class Task(Base):
    def __repr__(self):
        return (
            "<Task id='" + str(self.id) + "' name='" + self.name
            + "' 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 (
            "<Task id='" + str(self.id) + "' name='" + self.name
            + "' game_id='" + str(self.game_id)
            + " task_definition_id=" + str(self.task_definition_id) + "'>")
    __table__ = task_table
    task_definition_id = column_property(
        task_definition_table.c.id,
        task_definition_language_table.c.task_definition_id,
        task_table.c.task_definition_id)
    name = column_property(task_definition_language_table.c.name)
    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

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/328f63b3-dda4-4b59-a85b-52846e319d53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to