[eluser]matyhaty[/eluser]
[quote author="michaelfbradley" date="1363610203"]Hey - Really liking Datamapper.
I have two quick questions.
1. I was wondering if it's possible to define virtual attributes within the model?
Let's say for example I have a users model, and I want to explicitly define a virtual attribute called 'fullname', which uses the firstname and lastname fields from my DB?
2. Is it possible to define different validation requirements for various scenarios within the model? Let's say I have different validation requirements whenever when updating a record, versus creating a record.
Thanks,
M[/quote]
Hi
I'm not aware of any virtual options but layout of code might help here. Also are you using the array extension. If not, do.
So an example update/create prototype
Function edit($id = null)
{
If($id)
{ // your validation options for an edit }
Else
{ // validation options for a new entry }
// for virtual options lets say your form
// has firstname and surname
// but you store in your db 'fullname'
$data = $_post;
$data['fullname'] = $data[firstname] + $data[lastname]
// save entry.
$user = new User($id);
$user->save-from-array($data)(
// I'm pretty sure that save from array finction name is wrong
// check docs (I'm writting this on an iPhone!!!)
}