I've also just noticed this line in the Doctrine documentation:

"Now it is impossible to create orders with a product_id that does not 
appear in the product table."

Just above here:

http://www.doctrine-project.org/documentation/manual/1_0/en/defining-models
:relationships#foreign-key-constraints:integrity-actions

Which follows from this schema:

Order:
   tableName: orders
   columns:
     product_id: integer
     quantity: integer
   relations:
     Product:
       local: product_id
       foreign: id

Can anyone comment on whether it is therefore possible to create a 
record without a parent record?

Cheers,

Tom

Tom Haskins-Vaughan wrote:
> Thanks again, David.
> 
> I have tried owingSide: true and false. No joy.
> 
> I also tried onUpdate: SET NULL, which didn't work either.
> 
> I tried explicitly defining Cart::id but then I got a problem loading 
> fixtures.
> 
> In the generated MySQL table, I can create a Cart row with a null 
> buyer_id, so the SQL is at least being interpreted correctly.
> 
> I'm not sure how to dump the SQL. I'm using the following code to create 
> the cart, so where do I call the ->getSQL()?
> 
> $cart = new Cart();
> $cart->setBuyerId(null);
> $cart->save();
> 
> Cheers,
> 
> Tom
> 
> David Ashwood wrote:
>> Humm - so you currently have something like:
>>
>>  Cart:
>>     actAs: [Timestampable]
>>     columns:
>>       id:
>>         type: integer(4)
>>         primary: true
>>       buyer_id:
>>         type: integer(4)
>>         notnull: false
>>       is_default:
>>         type: Boolean
>>         default: false
>>     relations:
>>       Buyer:
>>         class: sfGuardUser
>>         local: buyer_id
>>         foreign: id
>>
>> I'd expect the above to work without needing a Buyer (infact you shouldn't
>> need the nullable on the field).  Did you clear the cache and
>> doctrine:build-all-reload?
>> I'd examine the relations options further here:
>> http://www.doctrine-project.org/documentation/manual/1_0/en/defining-models:
>> relationships#introduction
>>
>> Look at defining extra elements under relations: the owningSide, foreignType
>> and onUpdate.
>> I think the issue might be with the owning side of the relationship.
>>
>> Download the Doctrine 1.0 PDF (the website is acting a little odd at the
>> moment) and checkout around page 95.
>> I have some things to finish up here but I'll knock up a test app to try a
>> few things out.
>>
>>
>> -----Original Message-----
>> From: symfony-users@googlegroups.com [mailto:symfony-us...@googlegroups.com]
>> On Behalf Of Tom Haskins-Vaughan
>> Sent: 20 May 2009 05:08
>> To: symfony-users@googlegroups.com
>> Subject: [symfony-users] Re: Doctrine problem trying to add null relation
>> object
>>
>>
>> Thanks, David.
>>
>> I already have cart::id and buyer_id is nullable by default. Any other 
>> suggestions?
>>
>> David Ashwood wrote:
>>> Throw in a cart_id and mark the buyer_id as nullable.
>>>
>>> -----Original Message-----
>>> From: symfony-users@googlegroups.com
>> [mailto:symfony-us...@googlegroups.com]
>>> On Behalf Of Tom Haskins-Vaughan
>>> Sent: 19 May 2009 22:01
>>> To: symfony-users@googlegroups.com
>>> Subject: [symfony-users] Doctrine problem trying to add null relation
>> object
>>> symfony 1.2
>>>
>>> Hi,
>>>
>>> I have the following shopping cart class:
>>>
>>> Cart:
>>>    actAs: [Timestampable]
>>>    columns:
>>>      buyer_id:           { type: integer(4) }
>>>      is_default:         { type: boolean, default: false }
>>>    relations:
>>>      Buyer:
>>>        class: sfGuardUser
>>>        local: buyer_id
>>>        foreign: id
>>>
>>> Now, when someone visits the site, and before logging in, I need to 
>>> creat a new Cart with no buyer id. But When I try to do this I get:
>>>
>>> 500 | Internal Server Error | Doctrine_Validator_Exception
>>> Validation failed in class sfGuardUser
>>>
>>> 1 field had validation error:
>>>
>>> * 1 validator failed on username (notnull)
>>>
>>> So, I assume Doctrine is trying to create a new sfGuardUser to add to 
>>> the cart. But I want the buyer_id to be null until s/he logs in.
>>>
>>> Any ideas?
>>>
>>> Thanks.
>>>
>>> Tom
>>>
>>>
>>>
>>
>>
> 
> > 
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to