Yii Framework Forum: help in relations - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

help in relations to retrieve data from a table whose linked to another ... table Rate Topic: -----

#1 User is offline   equatorlounge 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 03-October 11
  • Location:rondebosch, cape town

Posted 28 October 2011 - 02:52 PM

3 tables: agent (id, user_id, agency_id) user (id, person_id) person (id, name, surname). i want the user_id field in agent table to display the name and surname from the person table in a drop down... any idea ?
0

#2 User is offline   equatorlounge 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 03-October 11
  • Location:rondebosch, cape town

Posted 28 October 2011 - 03:36 PM

i have 3 tables: agent (id, user_id, agency_id) user (id, person_id) person (id, name, surname).

i want the user_id field in agent table to display the name and surname from the person table in a

drop down... any idea ?

cos this name, surname from my person table to display in a dropdown for the user's field in the

create new agent is driving me nuts :(

is the relations functions for the agent model is 'users' => array(self::HAS MANY, 'Person', 'user_id') ?

if i could get a link on how to display the name,surname of the person table inside my dropdown field for choose user in my 'create new agent' form, i would be relieved
0

#3 User is offline   equatorlounge 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 03-October 11
  • Location:rondebosch, cape town

Posted 28 October 2011 - 05:08 PM

so my User model will consist of the following relations
return array(
'touroperatoragents' => array(self::HAS_MANY, 'Agent', 'el_user_id'),
'users' => array(self::BELONGS_TO,'Person','el_person_id')
)
0

#4 User is offline   equatorlounge 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 03-October 11
  • Location:rondebosch, cape town

Posted 28 October 2011 - 05:10 PM

for the above mentioned code i was asked to define the relations in those models from which you'll access the related data. e.g. if you want to fetch all agents for a user, you'll have to declare a has_many relationship to your agent model inside your user model. if you want to fetch the person the user belongs to, you have to declare a belongs_to relationship to your person model in your user model.

if you want to fetch all users for a person, you have to declare a has_many relationship to your user model in your person model

View Postequatorlounge, on 28 October 2011 - 05:08 PM, said:

so my User model will consist of the following relations
return array(
'touroperatoragents' => array(self::HAS_MANY, 'Agent', 'el_user_id'),
'users' => array(self::BELONGS_TO,'Person','el_person_id')
)

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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