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.

Archive /

Our old forums are still available as a read-only archive.

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

Datarelations Member - Event


Go to End


1922 Views

Avatar
snichme

Community Member, 2 Posts

13 December 2008 at 4:19am

Edited: 13/12/2008 4:19am

I've a problem with datarelations.

On my page I've some Events that each Member can sing up to. The problem is that the member has to be able to choose what to drink and eat for each Event. I've tried to solve it using an extra dataobject called Participant like this

EventPage
many_many: Participant

Participant
Has_many: EventPage
Has_one: Member

Member
has_one: Participant

Each member can sing up to the event through a form on the event-page.
The problem is that I dont know how to save the information in the correct way.

File: EventPage

$p = new Participant();
if(isset($data['toDrink'])) {
	$p->Drink = $data['toDrink'];
}
if(isset($data['Vegetarian'])) {
	$p->Vegetarian = $data['Vegetarian'];
}
$p->Member = Member::CurrentUser();
$e = $p->Events();
$e->add($this);
$p->write(); 
$existingParticipants = $this->Participants();
$existingParticipants->add($p);

The fields
- Member.ParticipantID
- Participant.MemberID
and the table
- Participant_Events

is still empty after the member has signup => The member doesnt get signed up..