Thank you Michael!
I've got a follow-up question if anyone's up to it. I've changed my
classes and mappings to the following:
class QType(object):
...
questions = association_proxy('joinObj', 'questions',
creator=_create_joinObj)
sections = association_proxy('joinObj', 'sections')
class Question(object):
...
section = association_proxy('joinObj', 'section')
mapper(QJoin, join_table, properties={
'type' :relation(QType),
'sections' :relation(Section, backref='parent'),
'questions' :relation(Question, backref='parent')
})
mapper(Question, questions_table)
mapper(Section, sections_table)
mapper(QType, types_table, properties={
'joinObj' :relation(QJoin)
})
And it's working, thanks to Michael's help. Here's my question: I
have three interrelated thing: Questions, Sections, Types. I
struggling to do the mappings that would allow these:
1) Given a Type, what are all the Sections (ignoring the Questions;
grouping by Sections)?
my_type = Type()
my_sections = my_type.sections ??
2) Given a Type and Section, what are the Questions?
my_type = Type()
my_questions = my_type.sections[0].questions ??
3) Given a Type, what are all the Questions (ignoring the Sections;
grouping by Questions)?
my_type = Type()
all_questions = my_type.questions ??
I appreciate the help,
Matt
On May 5, 3:32 pm, Michael Bayer [EMAIL PROTECTED] wrote:
On May 5, 2008, at 5:11 PM, Matt Haggard wrote:
I've got a kind of goofy schema, and I'm trying to map it. I've got
Questionnaire types, Sections and Questions all joined in a single
association table:
join_table : type_id | section_id | question_id
questions_table : id | question_text
sections_table : id | section_name
types_table : id | type_name
So, a single question can appear in different sections for different
types. How do I do the mapping? This is what I've got, and it
doesn't work.
mapper(Question, questions_table)
mapper(Section, sections_table, properties={
'questions':relation(Question, backref='section',
secondary=join_table)
})
mapper(QType, types_table, properties={
'sections':relation(Section,
backref = 'type',
secondary = join_table
primaryjoin = types_table.c.id==join_table.c.type_id,
secondaryjoin = join_table.c.section_id==sections_table.id
)
})
your table is not a many-to-many table, its just another entity table
with associations to other entities. secondary is not the
appropriate construct in this case; use an association mapping :
http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_relatio...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---