Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [SOLVED] 1-N relationship...how create data in child?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 718 Views
  • biapar
    Avatar
    Forum Moderator
    435 Posts

    [SOLVED] 1-N relationship...how create data in child? Link to this post

    Hi,

    I've a 1-n relation that is 1 product ; N quotes...
    I solved how create quotes, but ProductID value in child is always 0. How Do I insert relation data?
    Code:

    $myMember = DataObject::get_by_id('Member',$People);
    if ($myMember) {
    $people_tmp=$myMember->FirstName." ".$myMember->Surname;

    }
    $InfoQuota = new ProductQuota();

    $InfoQuota->People=$people_tmp;
    $InfoQuota->Quota=$QuotaNumber;
    echo "Product" . $ProductID;
    $InfoQuota->ProductID=$ProductID;
    var_dump($InfoQuota);
    $InfoQuota->write();
    }

    Thank you

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: [SOLVED] 1-N relationship...how create data in child? Link to this post

    echo "Product" . $ProductID;

    Does that correctly output your product id? You don't mentioned where that comes from so I'm going to assume that is set.

    This line should set the relation - $InfoQuota->ProductID=$ProductID; which is what you are doing so that should be working as long as $ProductID is set.

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: [SOLVED] 1-N relationship...how create data in child? Link to this post

    If so...I need to investigate on ProductID parameter...

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: [SOLVED] 1-N relationship...how create data in child? Link to this post

    Problem was from $this->ProductID to $this->ProductID

    Thank you

    718 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.