On Nov 11, 2010, at 7:50 PM, Sergey V. wrote:

> 
>> relationship() expects a class or a mapper instance, not a string. I
>> got this error:
>> 
>> ArgumentError: relationship 'available_deals' expects a class or a
>> mapper argument (received: <type 'str'>)
> 
> Hmm... I'm not sure what I'm doing wrong but passing strings to
> relation() definitely works for me:

The difference here is that usage of declarative adds an extra handler to 
relationship() calls, such that strings passed for most of its arguments are 
converted to callables which are later evaluated when the mapper structure is 
initialized.

You should be able to use relationship() in a "deferred argument " style 
without declarative by using lambdas, i.e.:

relationship(lambda: MyClass, primaryjoin=lambda:MyClass.foo==OtherClass.bar)

But generally usage of mapper() wasn't intended to provide any "tricks" around 
import issues.  You can always use mapper.add_property(...) to attach things as 
needed, and class_mapper(Class) to call up any mapper anywhere.

> 
> 
> class Host(Base):
> 
>    __tablename__ = 'hosts'
>    id = sa.Column(sa.Integer, primary_key = True)
>    ...
>    datacentre_id = sa.Column(sa.Integer,
> sa.ForeignKey('datacentres.id'))
>    datacentre = sa.orm.relation('Datacentre', backref='hosts')
> 
> Can it be because I'm using declarative? In my case I don't even need
> to import Datacentre class before I declare Host class.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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