Good morning guys,
I'm looking for a way in which I can query my database for records which
meet multiple, optional arguments. I'm looking to encapsulate access to this
using a service layer, I want to create a method like this:
def get_foos(self, foo_id="", foo_firstname="", foo_lastname=""):
foos = session.query(Foo).filter_by(foo_id=foo_id,
foo_firstname=foo_firstname, foo_lastname=foo_lastname)
return foos
Now, the thing I'm struggling with is how to make all those attributes
optional. Because at the moment I call that method like so:
get_foos(foo_id=2)
I get no results returned because SQLAlchemy is looking for records that not
only have an id of 2 but also have a first and last name which is an empty
string.
What I would ideally like to do is only have it filter by the arguments for
getfoos() which are not empty strings. This would allow me to build a more
reusable query method.
Is this possible? And how would one achieve it?
Cheers,
Heston
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---