Hi All,

Happy X'max :)

I'm implementing a tag schema using sqlalchemy, I follow the official
document's way:

articles_table = Table('articles', metadata,
   Column('article_id', Integer, primary_key = True),
   Column('headline', String(150), key='headline'),
   Column('body', TEXT, key='body'),
)

keywords_table = Table('keywords', metadata,
   Column('keyword_id', Integer, primary_key = True),
   Column('keyword_name', String(50))
)

itemkeywords_table = Table('article_keywords', metadata,
   Column('article_id', Integer, ForeignKey("articles.article_id")),
   Column('keyword_id', Integer, ForeignKey("keywords.keyword_id"))
)

# class definitions
class Keyword(object):
   def __init__(self, name):
       self.keyword_name = name

class Article(object):
   pass

mapper(Keyword, keywords_table)

# define a mapper that does many-to-many on the 'itemkeywords'
association
# table
mapper(Article, articles_table, properties = dict(
   keywords = relation(Keyword, secondary=itemkeywords_table,
lazy=False)
   )
)

just that I didn't want to minimize duplication, so I remove all the
table name prefix in the column name, that is instead of "keyword_name"
I choose "name" (since it's in keyword table it must be keyword name),
here's the problem, if I try to get all the articles which have a
specific keyword, the doc says:

# select articles based on a keyword.  select_by will handle the extra
joins.
sqlarticles = session.query(Article).select_by(keyword_name='politics')


but since I rename the keyword_name to name, how can I do this query
now ?
or there's no easy way to do it so I should duplicate all the table
name as the prefix in column name(which is ugly IMHO  ;))?

Thanks
Qiang


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to