Yii Framework Forum: adding record in has man relation - Yii Framework Forum

Jump to content

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

adding record in has man relation i am getting problem while adding new record in has many relation Rate Topic: -----

#1 User is offline   arslan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 05-August 11

Posted 26 October 2011 - 10:36 PM

Hi

I have many relation between notes and contact, a contact can has many notes and here is relation of contact

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'agent' => array(self::BELONGS_TO, 'Agents', 'agent_id'),
            'notes' => array(self::HAS_MANY, 'Note', 'contact_id'),
            'contactGroup'=>array(self::HAS_MANY,'ContactGroup','contact_id')
        );
    }


I want to add new note from a contact relation, when i have contact object it has many notes and i can see array here $contact->notes, now i want to add one more record into array, here is some which i want to acheive but don't know exact way

$contact->notes[] = new Note();
$contact->notes[]->attributes = $_Post['Note'];
$contact->notes[]->save();


Please guide me how can i acheive this
0

#2 User is offline   Khoa Le 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 11-April 11

Posted 27 October 2011 - 04:53 AM

$note = new Note();
$note->attributes = $_Post['Note'];
$note->contact_id =$contact->contact_id;
$note->save();

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