Stefano,
Thanks! Your script helped me narrow down the problem.
My Rating object has multiple Subrating objects. So in my real code, I
have something like:
class SubRating1(Base):
    __tablename__ = 'subratings1'
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(32), unique=True)

class SubRating2(Base):
    __tablename__ = 'subratings2'
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(32), unique=True)

class SubRating3(Base):
    __tablename__ = 'subratings3'
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(32), unique=True)

And then my Rating looks like:
class Rating(Base):
    __tablename__ = 'ratings'
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(32), unique=True)
    subrating1_id = Column(Integer, ForeignKey('subratings1.id'))
    subrating1 = relationship("SubRating1", backref=backref("rating",
cascade="all, delete-orphan", uselist=False))
    subrating2_id = Column(Integer, ForeignKey('subratings2.id'))
    subrating2 = relationship("SubRating2", backref=backref("rating",
cascade="all, delete-orphan", uselist=False))
    subrating3_id = Column(Integer, ForeignKey('subratings3.id'))
    subrating3 = relationship("SubRating3", backref=backref("rating",
cascade="all, delete-orphan", uselist=False))

Everything works great when I create and assign all 3 subratings to
the rating object before I add it to the session.
However, I need to be able to create a Rating that only has 1 or 2
subratings, and the other subratings absent.
When I do that, SQLAlchemy tells me:
InterfaceError: (InterfaceError) Error binding parameter 0 - probably
unsupported type. u'SELECT SubRating2.id AS subrating2_id \nFROM
subratings2 \nWHERE subrating2.id = ?' (<symbol 'NEVER_SET>,)

The above error is when I set Ratings's subrating1 and subrating3, but
not subrating2.
How do I avoid this error?

On Aug 6, 6:16 am, Stefano Fontanelli <s.fontane...@asidev.com> wrote:
> Il 06/08/11 00.32, Aviv Giladi ha scritto:
>
> > Hi Stefano,
> > I create and add a Rating and Subrating (both end up in the DB no
> > problem).
> > Then, I call session.delete(rating_obj) and commit it. I look at the
> > DB, and the Rating is gone, but the SubRating is still there.
> > The DB shows that the Rating has the correct Subrating's ID..
>
> Hi Aviv,
> I attached the code you sent me.
>
> I move 'cascade' as I told you and everything works. See the log that I
> pasted at the bottom of the script.
>
> --
> Ing. Stefano Fontanelli
> Asidev S.r.l.
> Via Osteria Bianca, 108/A 50053 Empoli (Firenze)
> Tel. (+39) 333 36 53 294   Fax. (+39) 0571 1 979 978
> E-mail: s.fontane...@asidev.com   Web:www.asidev.com
> Skype: stefanofontanelli
>
>  test.py
> 7KViewDownload

-- 
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