use MyApp::Contact;Basically what we're doing is using the new() method to build our contact manually by putting in a hash with the email address and name. Once that's complete, we simply make a quick call to save() and Rose::DB will insert it into the database.
$u = MyApp::Contact->new(name => 'Moe', email => 'moe@thestooges.com');
$u->save;
$moe = MyApp::Contact->new(email => 'moe@thestooges.com'); $moe->load; print "User's name is ".$moe->name.", email address is ".$moe->email.", database id is ".$moe->id.".\n";
$u = MyApp::Contact->new(name => 'Moe', email => 'moe@thestooges.com');That should insert the record into the database and MySQL will create an ID for it. Next we try loading the record by it's email address to see if it worked:
$u->save;
$moe = MyApp::Contact->new(email => 'moe@thestooges.com'); $moe->load;and finally print the record and look at all the values:
print "User's name is ".$moe->name.", email address is ".$moe->email.", database id is ".$moe->id.".\n";Which of course, should read something like:
User's name is Moe, email address is moe@thestooges.com, database id is 3.\n";
Previous: Using Rose:DB in Your Application
