On Jun 17, 6:39 am, Mike Conley <mconl...@gmail.com> wrote:
> users.room is the id of a room, not an actual room
>
>          u.room = r.id
>
> will fix the problem
>
> However, if you want to use a SA relation, you didn't declare it yet.
>
> You can do this to make a relation
>
>      users_table = Table('users', metadata,
>                        Column('id', Integer, primary_key=True),
>                        Column('name', String(50)),
>                        Column('room_id', ForeignKey('rooms.id'))
>                        )
>
>     mapper(user, users_table,
>         properties={'room' : relation(room)})
>
> now room is a pointer to a room object identified in the database by room_id
> and
>
>     u.room = r
>
>  will work OK
>

Right, that seems resonable.

Three other questions:

1) Is there shortcut for this in the ForeignKey() constructor?

2) Is this considered typical SQLAlchemy code?

3) Can this relation's objects be made "read-only"?  That is:
"u.room = new_room" would work, but this would not:  "u.room.name =
'kitchen'"

Thank you,
:)




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to