From: Jonathan Ellis Date: Tue, 23 Jan 2007 06:28:24 +0000 (+0000) Subject: add example of joining to labeled table X-Git-Tag: rel_0_3_4~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f68e1f45022b04aeaa0f88dee4085412a3cd8d2d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git add example of joining to labeled table --- diff --git a/lib/sqlalchemy/ext/sqlsoup.py b/lib/sqlalchemy/ext/sqlsoup.py index f9c13d3887..390a2c16df 100644 --- a/lib/sqlalchemy/ext/sqlsoup.py +++ b/lib/sqlalchemy/ext/sqlsoup.py @@ -159,6 +159,12 @@ to disambiguate columns with their table name: >>> db.with_labels(join1).c.keys() ['users_name', 'users_email', 'users_password', 'users_classname', 'users_admin', 'loans_book_id', 'loans_user_name', 'loans_loan_date'] +You can disambiguate just one table in a join by applying labels to that table, +and joining on the returned object: + >>> labeled_loans = db.with_labels(db.loans) + >>> db.join(db.users, labeled_loans, isouter=True).c.keys() + ['name', 'email', 'password', 'classname', 'admin', 'loans_book_id', 'loans_user_name', 'loans_loan_date'] + Advanced Use ============ @@ -196,7 +202,10 @@ just needs to be unique within the select, and not necessarily correspond to a >>> years_with_count.select_by(published_year='1989') [MappedBooks(published_year='1989',n=1)] -Obviously if we just wanted to get a list of counts associated with book years once, raw SQL is going to be less work. The advantage of mapping a Select is reusability, both standalone and in Joins. (And if you go to full SQLAlchemy, you can perform mappings like this directly to your object models.) +Obviously if we just wanted to get a list of counts associated with book years +once, raw SQL is going to be less work. The advantage of mapping a Select is +reusability, both standalone and in Joins. (And if you go to full SQLAlchemy, +you can perform mappings like this directly to your object models.) Raw SQL