3062 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1385 Views |
-
Need help with data model design

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 dataHow 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~ -
Re: Need help with data model design

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?
-
Re: Need help with data model design

19 June 2010 at 10:54am
Hello,
I'm very interresting by your code. Did you succeeded ?
-
Re: Need help with data model design

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)
-
Re: Need help with data model design

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
| 1385 Views | ||
|
Page:
1
|
Go to Top |


