Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User extends Member {
- private static $db = array(
- "FirstName" => "Text",
- "Age" => "Int",
- "Address" => "Text"
- );
- public static $has_one = array(
- 'Profile' => 'Profile'
- );
- public function onBeforeWrite()
- {
- parent::onBeforeWrite();
- if (! $this->Profile()->exists()) {
- $profile = new Profile();
- $profile->User = $this->ID;
- $profile->write();
- $this->ProfileID = $profile->ID;
- $this->update();
- }
- }
- <?php
- class Profile extends DataObject {
- public static $has_one = array(
- 'User' => 'User'
- );
- }
- public function addNew() {
- $NewUser = new User();
- $NewUser -> FirstName = "Jay Smith";
- $NewUser->write();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement