Shoot!! It works!! :D :D

---------------------- Parent.py (extract) ----------------------
# . . .
        child1 = relationship(
                "Child",
                uselist=True,
                primaryjoin=lambda: and_((Parent.id == Child.parent_id), 
(Child.type
== "VR")),
                collection_class=lambda: ZepConnector("VR")
                )
                
        child2 = relationship(
                "Child",
                uselist=True,
                primaryjoin=lambda: and_((Parent.id == Child.parent_id), 
(Child.type
== "CC")),
                collection_class=lambda: ZepConnector("CC")
                )
                
-----------------------
Do you know any documentation where I can understand "why"?  Conor
already mentioned
(http://groups.google.com/group/sqlalchemy/msg/d8fbbbff6d961332) the
importance of using lambdas, strings... to avoid mistakes,

------ Quote: ---------
    In SQLAlchemy you get around circular dependencies by:

        * Using strings as the target of ForeignKey()
        * Using class name strings as the target of a relation (declarative
          only)
        * Using strings or callables as primaryjoin/secondaryjoin arguments
          in a relationship()
---------------------------------

but I'd like to understand a little bit more how does it work (what's
going on internally) so I won't make similar errors in the future.

Thank you so much...

2010/11/9 Michael Bayer <mike...@zzzcomputing.com>:
>
> On Nov 8, 2010, at 6:36 PM, Hector Blanco wrote:
>
>> methods that I have implemented and that need to be there. That would
>> be the "ZepConnector" (and, for purposes of the example, it's method
>> foo() it's the one I need to use). As you can see in the following
>> lines, I randomly test its availability in the addChild1() method of
>> the Parent.
>>
>>       child1 = relationship(
>>               "Child",
>>               uselist=True,
>>               primaryjoin=lambda: and_((Parent.id == Child.parent_id), 
>> (Child.type
>> == "VR")),
>>               collection_class=ZepConnector("VR")
>>               )
>
> So this is incorrect - collection_class takes a class or other callable as an 
> argument that will produce an instance of your collection.  The ZepConnector 
> source you have below indicates that ZepConnector("VR") is an instance of the 
> collection.   You need to use a lambda: there.   The other errors you're 
> getting would appear to extend from that (and is also why __init__ is called 
> on ZepConnector - you're calling it yourself).
>
>
> --
> 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