Hi Michael,
Thanks for the quick reply :-)
To clarify things out, when you see Repository in my answers for this email,
please consider it DataMapper's Repository and not my own implementation of
the pattern said on my last message.
Answers below...
> Right now, the only thing that I think would "hurt" DDD in Ruby
> > applications is that I couldn't find an ORM that doesn't implement
> > Fowler's Active Record pattern.
>
> DataMapper does not. DataMapper implements... well, Data Mapper pattern.
>
In DM, when you do Person.create(...) it ends up being handled by
> Adapter#create,
> so in many ways, both DM and AR do it already, and it is a matter of
> taste to me.
>
My bad, I should've looked at the source before saying this, I thought it
was AR just because of 'entity.save()'
Still, we can't call Repository#create directly in our code. Well, we
actually can but then we would have to manage identity map ourselves because
the entity is being registered on identity map inside Resource#create. Maybe
this "management" could be moved to the repository since it is the "owner"
of the map, maybe not :-P
> So my questions are:
> > * Would it be hard to decouple CRUD operations from entities and
> > have something like (N)Hibernate session that holds identity map, does
> > CRUD and so on...?
>
> Can you give a specific example (with DM/Ruby code?)
For sure! Actually it is really simple.
First, regarding models definition, I think the way DM does the mapping is
awesome and I have nothing to say about that.
Here's some code:
dm_repository = {get a repository instance from DM}
# create
zoo = Zoo.new(:name => 'Awesome Town Zoo')
dm_repository.save(zoo)
# retrieve
zoos = dm_repository.all(Zoo)
zoo = dm_repository.first(Zoo)
# update
zoo.name = 'bla'
dm_repository.save(zoo)
# delete
dm_repository.destroy(zoo)
dm_repository.destroy_all(Zoo)
...
I know it is a matter of taste but maybe this can give us some more freedom.
Also we could keep all methods on DM::Resource (save, destroy...) and
delegate the whole operation to the repository so we don't break any code.
Do you see any problem with this?
> * Have you ever thought about these things and are there any plans
> > to do implement something like it?
> > * If not, do you guys think that would be possible to maybe create a
> > plugin for that?
> >
> > I hope you guys got my point but to make things even clear, I'd like
> > to decouple CRUD operations from entities and make those a repository
> > (http://martinfowler.com/eaaCatalog/repository.html) responsibility.
>
> What is missing (and would really make a difference in some
> situations) is Unit of Work, and it is on the road map.
> From my experience, Unit of Work with validations would simplify a lot
> of cases when you have to create multiple
> interdependent objects transactionally, but also have validations but
> with one nice list of errors.
>
> If someone could step up and implement that (it probably won't even
> require changes to existing code), it would really make a difference.
I could give it a shot but I would probably need some help from you guys
since I'm new to the language. But be sure I'll do my best to accomplish
that.
How do you think we would get an instance of it?
Repository#create_unit_of_work?
Just to let you guys know, I do have a bit of experience with ORMs, I'm also
helping on development of a ORM library written in PHP:
http://www.outlet-orm.org/
It is not as powerful as DM but I really like the way it works.
Welcome to DM, and I want to be honest with you: DM 0.9.x is buggy and
> some ideas did not work out so well.
> That's why all focus now is on 0.10 with completely rewritten tests
> and certain pieces of implementation.
> So if you are going to follow DM development, follow next branch and not
> master.
Cool, I'll check it out tomorrow. I've started using git today and I have to
spend some time playing around with it tonight.
Regards,
--
Fábio Rehm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---