Respect / Relational

A fluent, intuitive ORM for any relational database engine
http://respect.github.io/Relational
Other
243 stars 32 forks source link

Redesign and refactoring #4

Closed alganet closed 12 years ago

alganet commented 13 years ago

After great feedback from our users, we now believe its time for a cleaner and more powerful Respect\Relational. Major points in this refactor:

Schema cleanup

Although the idea of different schema providers is great, their implementation is incomplete and people rarely uses them. We should focus on removing different schemas and upgrading AbstractSchema+Infered to a component more close to the Mapper.

As a result of this, users are encouraged to always use the three main conventions for Respect\Relational.

Future new schema providers are not discarded, but we should focus on getting our API awesome before trying out different things.

Finders become Collections

Currently finders are the objects that represent node chains in a Relational query. For $mapper->post->author[3]->fetch(), which is the query for retrieving all posts from author 3, both post and author are instantiated as Finders.

We're planning to extend this to make these finders do more than querying. $mapper->post->author->persist($object) for example would persist the $object to a predefined set of collections (a post and a table author). This will allow users to reuse the $mapper->post->author better and have more cohesive, schema-less, objects.

This also deprecates persisting directly into a Mapper instance. Users should know where they're persisting.

Collection shortcuts

Collections are always hierarchical. They implement the composite pattern. This allow us to create collection shortcuts:

<?php
$mapper->postsFromAuthor = $mapper->posts->author; //create the shortcut and assign to the mapper
$posts = $mapper->postsFromAuthor[3]->fetchAll(); //retrieve posts from the author 3
$mapper->postsFromAuthor->persist($newPost); //persists a new post with author

We also need to make these changes reduce our codebase =)

After this, Respect\Relational will not be called an ORM anymore. We need a better name for this approach.

alganet commented 13 years ago

I've started this refactoring. Any tests are more than welcome =D Thanks.

alganet commented 13 years ago

Use cases for this refactoring: https://gist.github.com/1331604

augustohp commented 13 years ago

Collections question:

alganet commented 13 years ago

You mean entity classes?