Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

[SOLVED] 1-N relationship...how create data in child?


Go to End


4 Posts   1356 Views

Avatar
biapar

Forum Moderator, 435 Posts

27 June 2010 at 9:12pm

Edited: 30/06/2010 7:09pm

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

Avatar
Willr

Forum Moderator, 5523 Posts

28 June 2010 at 9:24am

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.

Avatar
biapar

Forum Moderator, 435 Posts

28 June 2010 at 10:46pm

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

Avatar
biapar

Forum Moderator, 435 Posts

30 June 2010 at 7:09pm

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

Thank you