diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-08-03 16:56:43 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-08-03 16:56:43 +0000 |
| commit | 45945dfc463d7af279184e13c72677c2090a7520 (patch) | |
| tree | 80541cb64b419450ac4c0968ec59dc67e80a7bc5 /doc | |
| parent | 475cc6f0c907dceaedd53dcb3a29099cc8d1fdfc (diff) | |
| download | sqlalchemy-45945dfc463d7af279184e13c72677c2090a7520.tar.gz | |
more edits
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/build/content/ormtutorial.txt | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/doc/build/content/ormtutorial.txt b/doc/build/content/ormtutorial.txt index 114766008..02a8b6ae2 100644 --- a/doc/build/content/ormtutorial.txt +++ b/doc/build/content/ormtutorial.txt @@ -374,9 +374,10 @@ Note that when we use constructed SQL expressions, bind paramters are generated To use an entirely string-based statement, using `from_statement()`; just ensure that the columns clause of the statement contains the column names normally used by the mapper (below illustrated using an asterisk): {python} - {sql}>>> result = session.query(User).from_statement("SELECT * FROM users").all() - SELECT * FROM users - [] + {sql}>>> session.query(User).from_statement("SELECT * FROM users where name=:name").params(name='ed').all() + SELECT * FROM users where name=? + ['ed'] + {stop}[<User('ed','Ed Jones', 'f8s7ccs')>] `from_statement()` can also accomodate full `select()` constructs. These are described in the [sql](rel:sql): @@ -410,7 +411,7 @@ There's also a way to combine scalar results with objects, using `add_column()`. (<User('mary','Mary Contrary', 'xxg527')>, u'wendy') (<User('fred','Fred Flinstone', 'blah')>, u'wendy') -## Building a One-to-Many Relation +## Building a One-to-Many Relation {@name=onetomany} We've spent a lot of time dealing with just one class, and one table. Let's now look at how SQLAlchemy deals with two tables, which have a relationship to each other. Let's say that the users in our system also can store any number of email addresses associated with their username. This implies a basic one to many association from the `users_table` to a new table which stores email addresess, which we will call `addresses`. We will also create a relationship between this new table to the users table, using a `ForeignKey`: @@ -764,7 +765,7 @@ Deleting Jack will delete both Jack and his remaining `Address`: ['jack@google.com', 'j25@yahoo.com'] {stop}0 -## Building a Many To Many Relation +## Building a Many To Many Relation {@name=manytomany} We're moving into the bonus round here, but lets show off a many-to-many relationship. We'll sneak in some other features too, just to take a tour. We'll make our application a blog application, where users can write `BlogPost`s, which have `Keywords` associated with them. |
