I'm new to SQLAlchemy and not sure exactly how to explain this in its
terminology, so please bear with me.
We moving to replace an in-house developed ORM with SQLAlchemy because it
works better with the software we want to use. One problem I have is that
we're working with some unnormalized tables that store multiple values in
certain columns. For example, a column "invnum" might be a varchar(20),
where the first four characters are a customer ID string, and the rest are
the the string representation of an integer invoice number. That is,
customer "Foo, Inc." has an invoice 123456, and that is stored
as "FOOI123456". Yes, this is unpretty, but we're working on it.
In the mean time, it's easy enough to create a property that returns the
customer ID, ala:
class Invoice(object):
def _getcustomer(self):
return self.invnum[:4]
customer = property(_getcustomer)
However, I also need to be able to search by that calculated value, ideally
with something like:
session.query(Invoice).get_by(customer='FOOI')
Is this even remotely possible? Our in-house ORM knew enough about our
table structure that it would generate SQL like:
select * from invoice where substr(invnum,1,4) = 'FOOI';
I've tried to RTFM, but I'm really a beginner with it and don't even know
what to search for yet.
--
Kirk Strauser
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---