On Aug 21, 2010, at 7:20 PM, Michael Hipp wrote:
> On 8/21/2010 6:00 PM, Michael Bayer wrote:
>> On Aug 21, 2010, at 5:16 PM, Michael Hipp wrote:
>>> How do I make this work with declarative?
>>
>> If you were to use string literals with remote_side here, its the full
>> expression would be a string, i.e. remote_side="Option.id_". But that's
>> not needed here since id_ as a Column is right there, so remote_side=id_ .
>
> I made that one change:
>
> class Option(Base):
> __tablename__ = 'options'
>
> id_ = Column(Integer, primary_key=True)
> parent_id = Column(Integer, ForeignKey('options.id_'))
> parent = relationship('Option', backref=backref('children', order_by=name,
> remote_side=id_))
well the next issue is that remote_side=id_ goes on the many-to-one side, in
this case "parent". The "children" backref is the one-to-many side.
also I committed a change in r3f975f5917c0 that will prohibit errors of the
variety of foreign_keys=['x', 'y', 'z'] and such since this is a very common
error.
>
> Now I get:
> TypeError: Incompatible collection type: None is not list-like
> File "C:\dropbox\dev\auction\play.py", line 286, in <module>
> opts2()
> File "C:\dropbox\dev\auction\play.py", line 257, in opts2
> opt.start()
> File "C:\dropbox\dev\auction\options\logic.py", line 40, in start
> rec = Option(name='__top__')
> File "C:\dropbox\dev\auction\<string>", line 4, in __init__
> File "C:\dev\virtenvs\auction\Lib\site-packages\sqlalchemy\orm\state.py",
> line 104, in initialize_instance
> return manager.events.original_init(*mixed[1:], **kwargs)
> File "C:\dropbox\dev\auction\options\models.py", line 47, in __init__
> self.parent = parent
> File
> "C:\dev\virtenvs\auction\Lib\site-packages\sqlalchemy\orm\attributes.py",
> line 154, in __set__
> instance_dict(instance), value, None)
> File
> "C:\dev\virtenvs\auction\Lib\site-packages\sqlalchemy\orm\attributes.py",
> line 755, in set
> lambda adapter, i: adapter.adapt_like_to_iterable(i))
> File
> "C:\dev\virtenvs\auction\Lib\site-packages\sqlalchemy\orm\attributes.py",
> line 771, in _set_iterable
> new_values = list(adapter(new_collection, iterable))
> File
> "C:\dev\virtenvs\auction\Lib\site-packages\sqlalchemy\orm\attributes.py",
> line 755, in <lambda>
> lambda adapter, i: adapter.adapt_like_to_iterable(i))
> File
> "C:\dev\virtenvs\auction\Lib\site-packages\sqlalchemy\orm\collections.py",
> line 530, in adapt_like_to_iterable
> given, wanted))
>
> Any help?
>
> Thanks,
> Michael
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.