The explanation of DAO really cleared that up.
Just so I'm understanding you correctly with respect Data Mapper, I'm going to present an example and you let me know if I'm right.
I have a 'Message' model, for this particular model I'll instantiate a mapper that uses db as a persistent store. A message has a body, date, status and sender. The message may also have several recipient.
This results in a db structure of:
sender: [U]id[/U] (primary key), name (varchar), email (text), status (enum['active','inactive'])
message: [U]id[/U] (primary key), [U]sender_id[/U] (int), body (text), date (datetime), status (enum['sent','draft'])
message_recipient: [U]message_id[/U] (int), [U]sender_id[/U] (id)
Using my mapper I would handle the relation between the three tables. So a method like 'getMessage' would return my message complete with sender and recipients.
i.e.
// SQL Mapper example
$message = new Message(new SQL_MessageMapper());
$message->getMessage(492);
$sender_name = $message->sender->name;
$recipients = '';
foreach($message->recipient as $recipient) {
$recipients .= $recipient->name;
}
$message_body = $message->body;
An XML store might have the recipients as part of the message itself, but by implementing the mapper interface the result of my getMessage should still be the same.
i.e.
// XML store
<message id="492" sender_id="5" status="active">
<body>Some really clever message, voicing my displeasure about the state of affairs.</body>
<date>2010-05-12 11:23:09</date>
<status>draft</status>
<recipients>
<recipient>5</recipient>
<recipient>29</recipient>
<recipient>439</recipient>
<recipients>
</message>
// XML Mapper example
$message = new Message(new XML_MessageMapper());
$message->getMessage(492);
$sender_name = $message->sender->name;
$recipients = '';
foreach($message->recipient as $recipient) {
$recipients .= $recipient->name;
}
$message_body = $message->body;
Does all this seem correct?