Yii Framework Forum: How Gii Recognizes Has_One Relations - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How Gii Recognizes Has_One Relations Rate Topic: -----

#1 User is offline   galopez 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 13-November 12
  • Location:Cienfuegos, Cienfuegos, Cuba

Posted 14 November 2012 - 11:18 AM

Hi, I just recently found a case where I need to use a HAS_ONE relation but defining a foreign key in a table generates a HAS_MANY relation in the model when using Gii. How can I get a HAS_ONE relation?
Thanks in advance.
0

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 800
  • Joined: 02-July 10
  • Location:Central Poland

Posted 15 November 2012 - 02:30 AM

just change generated self::HAS_MANY to self::HAS_ONE
there is no difference in database representations of both cases so the generator cannot determine which to choose, but HAS_MANY covers all possibilities (when there is only one dependent record you will just get one record in array). Also - this is main benefit of scaffolding scenario: you generate base code but then you can adapt it and change the way you want
red
0

#3 User is offline   galopez 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 13-November 12
  • Location:Cienfuegos, Cienfuegos, Cuba

Posted 15 November 2012 - 10:09 AM

View Postredguy, on 15 November 2012 - 02:30 AM, said:

just change generated self::HAS_MANY to self::HAS_ONE


Ok. This is my current approach. Doubts cleared. Thanks again
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users