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


-- 
Mike Conley



On Wed, Jun 17, 2009 at 2:44 AM, AF <allen.fow...@yahoo.com> wrote:

>
> I'm probably just missing something... here is my code:
>
> engine = create_engine('sqlite:///:memory:', echo=True,
> convert_unicode=True)
> Session = sessionmaker(bind=engine)
> session = Session()
> metadata = MetaData()
>
> users_table = Table('users', metadata,
>                        Column('id', Integer, primary_key=True),
>                        Column('name', String(50)),
>                        Column('room', ForeignKey('rooms.id'))
>                        )
>
> rooms_table = Table('rooms', metadata,
>                        Column('id', Integer, primary_key=True),
>                        Column('name', String(50))
>                        )
>
> metadata.drop_all(engine)
> metadata.create_all(engine)
>
> class user(object):
>    pass
>
> class room(object):
>    pass
>
>
> mapper(user, users_table)
> mapper(room, rooms_table)
>
>
> u = user()
> r = room()
> session.add_all([u,r])
> session.commit()
> [OK]
>
> u.room = r
> session.commit()
> [ERROR: InterfaceError: (InterfaceError) Error binding parameter 0 -
> probably unsupported type. u'UPDATE users SET room=? WHERE users.id
> = ?' [<__main__.room object at 0xa9a9b4c>, 1] ]
>
>
> Any ideas?  Am I doing this wrong?
>
> 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