Which also explains why ActiveRecord has been hyped to death by everyone since RoR was releasedIndeed, it's also become apparent why there are quite large frameworks available for ORM! (It was mostly this that had me intrigued - "why would something like that need a large framework?")
Object Relational Mapping
Moderator: General Moderators
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
That tutorial is also showing Active Record (and it's from 2004). And the examples that you and Maugrim showed are also Active Record. Which makes me think that Active Record is probably really the solution you are looking. I should note that Active Record often has some O/RM like functionality added. For example, Rail's Active Record generates its mappings through convention -- which is a pretty common scheme.Jenk wrote:I'm getting confused now though, because I just spotted a PHPBuilder tutorial that shows my first example to be more correct than the latter :\
http://www.phpbuilder.com/columns/mathi ... 40309.php3
(Though I am more inclined to believe the tutorial is mistaken (or rather my take on it) as it makes perfect sense that my first example was/is an active record.. it's a single record, and it's active.. tada!)
Real O/RM can be a great solution, but you need to have a problem that it solves. Usually that problem is that the database schemas are out of your control and change often enough to be a problem. That's not the reality of most web applications.
Also, a comment on your code. It really should track objects by type so it can save them, but it does not need to store them like a Registry so they can be retrieved. So:
Code: Select all
class Mapper
{
private $_objects = array();
public function getInstance ($class)
{
// create instance
$obj = new $class;
// save reference so we can save it later (by class so we know which mappings to use)
$this->_objects[$class][] = $obj;
return $obj;
}(#10850)
I'm not looking to solve a problem, I'm looking to gain an understanding 
By what you're saying, the difference between an OR mapper and an Active Record is whether the object saves itself or not.. regardless of the actual mapping element provided by a 3rd object.
In short, my understanding is as follows:
ORM:
An object is in disregard for what, where and how it's state and/or data will be saved. A mapper will take care of that.
Active Record:
This object will save it self. (Hallelujah, another [s]soul[/s] object saved!) It has a direct 1 object to 1 record relationship.
By what you're saying, the difference between an OR mapper and an Active Record is whether the object saves itself or not.. regardless of the actual mapping element provided by a 3rd object.
In short, my understanding is as follows:
ORM:
An object is in disregard for what, where and how it's state and/or data will be saved. A mapper will take care of that.
Active Record:
This object will save it self. (Hallelujah, another [s]soul[/s] object saved!) It has a direct 1 object to 1 record relationship.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US