Jump to:

3377 Posts in 1001 Topics by 714 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Need help with data model design

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1489 Views
  • Piklets
    Avatar
    Community Member
    36 Posts

    Need help with data model design Link to this post

    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~

  • Piklets
    Avatar
    Community Member
    36 Posts

    Re: Need help with data model design Link to this post

    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?

  • Myrdhin
    Avatar
    Community Member
    67 Posts

    Re: Need help with data model design Link to this post

    Hello,

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

  • Piklets
    Avatar
    Community Member
    36 Posts

    Re: Need help with data model design Link to this post

    Yes, I did succeed.

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

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

  • Myrdhin
    Avatar
    Community Member
    67 Posts

    Re: Need help with data model design Link to this post

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

  • Piklets
    Avatar
    Community Member
    36 Posts

    Re: Need help with data model design Link to this post

    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

    1489 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.