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.

Data Model Questions

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


Reply

4 Posts   775 Views

Avatar
biapar

27 June 2010 at 9:12pm (Last edited: 30 June 2010 7:09pm), Forum Moderator, 435 Posts

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

28 June 2010 at 9:24am Forum Moderator, 5511 Posts

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

28 June 2010 at 10:46pm Forum Moderator, 435 Posts

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

Avatar
biapar

30 June 2010 at 7:09pm Forum Moderator, 435 Posts

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

Thank you