Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
Jonathon

Foreign Key Constraints

Recommended Posts

Morning Larry et al,

 

Regarding Foreign Key constraints in the command

 

CONSTRAINT fk_page_user
FOREIGN KEY (user_id)
REFERENCES yii_cms.user (id)
ON DELETE SET NULL
ON UPDATE NO ACTION)

 

ON DELETE - does that mean you're deleting the `user_id` of the page table (the table in which the sql command was written) or the `id` of the user table it references, or something else?

 

Thank you

 

Jonathon

Share this post


Link to post
Share on other sites

Good question. If you have a page record whose user_id value is 45, and the user record whose id value is 45 is deleted, the constraint dictates what is done with the page record. SET NULL would mean set that page record's user_id value to NULL.

  • Upvote 2

Share this post


Link to post
Share on other sites

Starting to learn today how important relationships are in setting up Yii models. I will have to mess around with the above also. Come on Larry we are out of Yii food, and we have empty stomachs .

Share this post


Link to post
Share on other sites

Good things come to those who wait. ;)

 

Relax, everyone. Quality will be affected if he rushes this book out. I'm sure everyone will gain on him not rushing this.

 

I was just winding him up, Ive been starting to mess around with Yii a little bit. And also reading the Alexander Makarov cookbook which is available. By the way Antonio there is three ways you can build queries in Yii, you can use Active Record which is the slowest, you can also use Query Builder or if you want the fatest you can use the Standard SQL(DAO) method. So with queries and Yii there is nothing to worry about, i remember you wrote about how inefficient code ignitor quiries were.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...