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

Need help with data model design


Go to End


6 Posts   2255 Views

Avatar
Piklets

Community Member, 36 Posts

13 March 2009 at 10:56pm

I can't seem to come up with a way to get this data model structure working:

Two types of users: patient and practice (at the moment they are defined as groups under Security in CMS)
Patient has one practice (has_one), practice has many patients(has_many?)

Patient has four fields: gender, program, progress, data
Practice needs to be able to access its patients and edit their data

How can I link a practice dataobject to a member in the practice security group
and link a patient dataobject to a member in the patients security group?

At the moment I edited sapphire/security/Member.php to add in extra fields for the patient, but thats not a good way at all, and it won't work when I try and implement the practice type of member!!

Hope thats easy enough to understand!
Thanks in advance~

Avatar
Piklets

Community Member, 36 Posts

14 March 2009 at 11:40am

I basically want two types of users, so I've looked up at http://doc.silverstripe.org/doku.php?id=member where there are some examples for extending Member.

If I create some code like this:

class Patient extends Member {
	static $db = array(
		"Gender" => "Enum('M,F')",
		"Program" => "Enum('C,E')",
		"Progress" => "Text",
		"Data" => "Text"
	);
	static $has_one = array(
		"Practice" => "Practice",
	);
}

and something like this:
class Practice extends Member {
	static $db = array(
		// fields here
	);
	static $has_many = array(
		"Patients" => "Patient",
	);
}

First of all, will the above code work?

Second of all, I have a registration module, with the main code being:

		// Create a new member and save the form into it
		$member = new Member();
		
		$form->saveInto($member);

		// Write to the databsae
		$member->write();

		// To do: add a status message on the form, using the standard form message system
		
		if($group = DataObject::get_one('Group', "ID = " . $this->defaultGroupID)) { 
		  $member->Groups()->add($group);
		}

Can I change 'new Member()' to 'new Practice()' or 'new Patient()'?

Then how would I create a foreach output of all a practice's patients?

Avatar
Myrdhin

Community Member, 70 Posts

19 June 2010 at 10:54am

Hello,

I'm very interresting by your code. Did you succeeded ?

Avatar
Piklets

Community Member, 36 Posts

19 June 2010 at 11:07am

Yes, I did succeed.

The code I gave worked, and for the foreach output I just did:

foreach($practice->Patients() as $patient)

Avatar
Myrdhin

Community Member, 70 Posts

20 June 2010 at 9:50pm

Ok. Thank you. I'll try your code.

Avatar
Piklets

Community Member, 36 Posts

20 June 2010 at 10:15pm

Feel free to ask if you want to see any more of my code regarding this, I've learnt a lot more since this thread started :)