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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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   1052 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