Hi everyone,
I have an unusual situation where I have a set of users that are
stored in an SQL DB as usual, and a set of news articles that are
stored elsewhere (not in an SQL database).
Usually, if both sets were stored in two DB tables, I'd be able to set
up a many-to-many relationship with them in SQLAlchemy with a joining
table. I'd have the following:
------
users_table = Table('tg_user', metadata,
Column('user_id', Integer, primary_key=True),
Column('user_name', Unicode(16), unique=True),
Column('email_address', Unicode(255), unique=True),
Column('display_name', Unicode(255)),
Column('password', Unicode(40)),
Column('created', DateTime, default=datetime.now),
)
articles_table = Table('articles', metadata,
Column('article_id', Integer, primary_key=True),
...
)
user_articles_table = Table('user_articles', metadata),
Column('user_id', Integer, ForeignKey('tg_user.user_id')),
Column('article_id', Integer, ForeignKey('articles.article_id')),
)
class User(object): pass
class Article(object): pass
mapper(User, users_table,
properties=dict(
articles=relation(Article, secondary=user_articles_table)))
------
What I need to do instead, with no Articles table, is store in
user_articles_table the user_id and article_id as I would usually,
but also have user.articles available as a list of integers (or some
wrapper that provided the integers).
Example:
>>> user = session.query(User).getFirst()
>>> user.user_id
1
>>> user.articles
[1, 294, 239, 390, 20, 489, 9378]
>>> user.articles.append(1000)
>>> session.commit() # INSERT INTO user_articles (user_id, session_id) VALUES
>>> (1, 1000);
Is this possible using SQLAlchemy? I'm aware I could simply perform
inserts and selects manually on the user_articles_table, but I'd quite
like SA to take care of that for me if at all possible.
I'm using SA 0.4
Thanks,
Nick
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---