On May 2, 2009, at 8:16 PM, Iain Duncan wrote:
>
> On Sat, 2009-05-02 at 09:41 -0400, Michael Bayer wrote:
>>
>> you'd set cascade="all, delete-orphan" on the Purchase.registration
>> side (in this case its your backref).
>
> Thanks Mike. So what is the recommended way of creating the attached
> item though, or is it supposed to happen automatically from the
> mapper?
you can say p.registration = r, or Purchase(registration=r), the
cascade option would enforce the constraint at flush time.
>
>
> Iain
>>
>>
>> On May 2, 2009, at 1:42 AM, Iain Duncan wrote:
>>
>>>
>>> Hi all, I have a mapper that looks like this:
>>>
>>> mapper( Registration, registration_table, properties={
>>> 'purchase': relation(Purchase,
>>> backref=backref('registration', uselist=False),
>>> cascade='all' ),
>>> })
>>>
>>> My registration table has a foreign key to purchases, and I want to
>>> make
>>> sure no registration exists without an associated purchase. I have
>>> the
>>> referrence backwards like a many-to-one because purchases may also
>>> be
>>> referred to in other tables ( like memberships ). Maybe this is
>>> not a
>>> good idea, not sure. Feel free to tell me. Should this perhaps be
>>> handled in a separate associating table with primary key with one
>>> column
>>> primary key constraints on it?
>>>
>>> But, my immediate problem is that I don't know what the correct
>>> way to
>>> make sure I create a purchase on creation of a registration. Should
>>> I be
>>> creating a purchase in the registration constructor? Should I be
>>> doing
>>> something like:
>>>
>>> r = Registration( purchase=Purchase() )
>>>
>>> Or should it work magically if I set up my cascade options
>>> differently?
>>>
>>> Thanks
>>> Iain
>>>
>>>
>>>
>>>>
>>
>>
>>>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---