I have been working hard on the next release of outlet. Since a lot of
the changes I was making were sort of experimental, I created a branch
to work on them: the 'many-to-many' branch.
The main features are:
* One-to-one and many-to-many relationships
* PHP-5.2's DateTime support
* Fluent-interface query API
* Eager fetching
The code currently passes the unit tests, but I feel it still needs some
polish.
There is one BC-incompatible change that was necessary to implement
many-to-many relationships without creating a linking entity in code:
Collections.
On this new version, relationship methods that currently return an array
of entities will now return a Collection object. This object implements
extends ArrayObject so it can be used in most situations where an array
can be used. Here is an example:
<?php
// entities should now be defined like this
class Project {
private $bugs;
...
public function getBugs () {
return $this->bugs;
}
public function setBugs(Collection $bugs) {
$this->bugs = $bugs;
}
...
}
// notice that you no longer need the addBug() method
...
$bugs = $project->getBugs();
// bugs is an instance of Collection
// but it behaves just like an array
// you can call count it
echo count($bugs);
// and you can use it in a foreach
foreach ($bugs as $bug) {
echo $bug->Description;
}
// to add a bug to a project
$bug = new Bug;
$bug->Title = 'Test Bug';
// you no longer need an addBug method
$project->getBugs()->add($bug);
// bug if you create it, you can still use it just the same
$project->addBug( $bug );
?>
Everything else works the same.
I would really appreciate any feedback on these changes, so if you're
adventurous, please check it out:
svn://knowledgehead.com/outlet/branches/many-to-many
Thanks,
Alvaro
Diogo Silva wrote:
> Alvaro,
>
> In a quick try It passed my projects unit tests without problems, but
> I still don't use any of the new features.
>
Great, Thanks for checking it out.
In the next few days I'll try to update the documentation and I'll
describe the new features in more details.
> ...
Thanks,
Alvaro
Hi Alvaro,
Just got back from vacation and started to try the many-to-many association but I couldn't find out how to configure and use it. I don't know how to create the config file and implement the entities classes.
Could you please send us a simple example of how it is done?
Thanks,
--
Fábio Rehm
Fabio R. wrote:
> You've already set up an account for me :-)
>
Whoops, I forgot, cool.
> Here's all the things I've done:
> - Created OutletQuery::offset parameter / method to support pagination
> together with OutletQuery::limit
> - Modified OutletMapper::insert method to make it call
> OutletMapper::saveManyToMany (please check out if I did in the right order,
> I called after saveOneToMany).
> - Fixed a bug in OutletMapper::insert when inserting entities with Date /
> DateTime properties (modified to call 'toSqlValue' method for casting
> values).
> - Modified OutletMapper::saveOneToMany to consider
> OutletCollection::removeAll()
> - Fixed a bug in OutletMapper::saveOneToMany. The method wasn't updating
> collection objects to the corresponding proxy.
>
Very nice. I see that you committed these, excellent. I'll add you to
the website as a developer.
> Still pending:
> - Eager fetch for one-to-many and many-to-many. I had a quick look at
> Doctrine and NHibernate source but couldn't figure out what they've done,
> maybe tonight I'll take another look.
> - Implementation for OutletQuery::limit and OutletQuery::offset for MS SQL.
> If you like the idea of subclassing I can do that.
> - When we get the one-to-many and many-to-many eager fetching to work we'll
> need to refactor OutletQuery::limit and OutletQuery::offset again since data
> will come 'denormalized'. (If you don't understand this point I can provide
> an example)
> - Unit tests (I'll try to do that tonight)
>
I'll have to look at these in more detail tomorrow.
>
> I'll try the library on PostgreSQL and I let you guys know what happens.
> I'm looking forward to test many-to-many associations.
>
> See ya,
> --
> Fábio Rehm
>
Thanks,
Alvaro
Not at all, the original message from Diogo just got lost with all the
other stuff (sorry, Diogo). I'll implement this on the trunk in the next
few days.
Thanks,
Alvaro