On Tue, Mar 20, 2018 at 3:02 AM, Jonathan Vanasco <[email protected]> wrote:
> this is silly - I realized I can just use a flag to run a different
> `orm.relationship` on the Admin and Public views:
>
> if ADMIN:
> records = orm.relationship(a.id=b.id)
> else:
> records = orm.relationship(and(a.id=b.id, b.id<1000))
>
> Is there any magical SqlAlchemy feature that would let me define
> setters/getters for a table's python column, while still keeping the
> underlying name of the column?
>
> to explain this poorly worded question...
>
> class Foo(Base):
> __tablename__ = 'foo'
> id = Column(Integer, primary_key=True)
> id_foo__context_a = Column(Integer, ForeignKey("foo.id"))
> id_foo__context_b = Column(Integer, ForeignKey("foo.id"))
>
> i'd like to replace `id_foo__context_a` with a property or setter/getter,
> which can still access/manipulate a stored value for a database field named
> `id_foo__context_a`. usually i rename the column or field to handle this,
> but in this case I can't.
if you just need a different name, rename it:
my_attr = Column('id_foo__context_a', Integer, ...)
>
> Perhaps there is an undocumented way to alter the backing db column of a
> sqlalchemy column, something like this...
>
> class Foo(Base):
> __tablename__ = 'foo'
> id = Column(Integer, primary_key=True)
> _id_foo__context_a = Column(Integer, ForeignKey("foo.id"),
> DatabaseColumn='id_foo__context_a')
> id_foo__context_b = Column(Integer, ForeignKey("foo.id"))
>
> @property
> def id_foo__context_a(self):
> return self._id_foo__context_a
>
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
--
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.
For more options, visit https://groups.google.com/d/optout.