On 9/20/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> For example class1 has a dependency on class2.  Other examples include
> single or multiple joins.
> ---------
> class class1(SQLObject):
>         param1 = ForeignKey('class2')
>
> class class2(SQLObject):
>       param1 = IntCol(length=255)
> ---------
>
> c1 = class1(param1=None)
>
> In a case such as this, how do I initialize a class1 object?  Do i need
> to initialize a class2 object first and then pass it into the class1
> initializer?  How would this work with a multiple join?
>

To answer your first question, there are two ways you could go about
this.  As you say, you could create a class2 object first and then
pass it to the class1 initialiser.  The other option is to slightly
modify your class1:

    class class1(SQLObject):
        param1 = ForeignKey('class2', default=None)

That way you can create a class1 instance and *then* pass it a class2
instance afterwards:

    a_class1_instance = class1()
    a_class2_instance = class2(param1=1)
    a_class1_instance.param1 = a_class2_instance

For the multiple join to work you'd have to specify it in your class2
definition:

    class class2(SQLObject):
        param1 = IntCol(length=255)
        class1s = MultipleJoin('class1')

You then access all class1's that reference a particular class2 like this:

    class1_list = a_class2_instance.class1s

Hope this helps.

Lee

-- 
Lee McFadden

blog: http://www.splee.co.uk
work: http://fireflisystems.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to