Hi
I have an application that was originally written to support just one
organisation. This app is now being modified to support multiple
organisations. As such I am trying to update the main bits of the model
to always filter queries by organisation_id, a new column I have added
in to the relevant tables.
For example, a class Users, used for authentication would have (so the
login/logout/reset password functions would be modified to use this):
class AllUser(Base):
__tablename__ = 'users'
id = sa.Column(sa.Integer, primary_key=True)
username = sa.Column(sa.Unicode(15), nullable=False, unique=True)
organisation_id = sa.Column(sa.Integer,
sa.ForeignKey('organisation.id'))
organisation = sa.orm.relationship('Organisation')
and the 'restricted' version would just show users from the organisation
(all other existing parts of the application would use this class for
its queries) :
class User(Base):
__table__ =
select([users_table]).where(users_table.c.organisation_id==session['organisation_id'])
id = sa.Column(sa.Integer, primary_key=True)
username = sa.Column(sa.Unicode(15), nullable=False, unique=True)
organisation_id = sa.Column(sa.Integer,
sa.ForeignKey('organisation.id'))
organisation = sa.orm.relationship('Organisation')
where session['organisation_id'] is the organisation id of the currently
logged in user.
Is this a sensible approach? Are there any concurrency issues I should
be aware of such as: would the __table__ select statement be
cached/reused from one request to the next?
How would I generate select based classes 'on the fly'/on a per request
basis (and would this be very slow if I did)?
Thank you very much in advance for any suggestions.
Damian
--
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.