coresmart / persistencejs

persistence.js is an asynchronous Javascript database mapper library. You can use it in the browser, as well on the server (and you can share data models between them).
http://persistencejs.org
1.73k stars 240 forks source link

Mix-in feature #13

Closed bjouhier closed 13 years ago

bjouhier commented 13 years ago

Hi Zef,

I've made a few commits this week-end.

The first ones are rather boring. Just a bit of cleanup in the type mapper (I moved the dbValToEntityVal and entityValToDbVal methods inside the type mapper block). I also documented the commit/rollback API (I still need to document the type mapper and provide a unit test - I'll do that a bit later).

The last commit is more interesting. I started to implement a "mix-in" feature. It enables polymorphic relationships. I have only tested a very basic case so far but I wanted to post it to get early feedback from you. I've put a bit of documentation in the readme and I've added a unit test.

I'm also planning to add support for "is a" relationships (classical inheritance) between entities. This should be easy once mix-ins are in place.

Thanks for the OR filters. I needed them.

PS: I commited another version this morning. I simplified the code to handle polymorphic relationships.

Bruno

zefhemel commented 13 years ago

Thanks a lot Bruno!

I really like the idea of adding Mixins to this. Some type of inheritance support was on my wish list for a long time now, maybe mixins is the way to go. I would like to make one change to the API, however. Generally I don't like "magic boolean arguments", a subtle "true" passed somewhere that quite radically change the meaning of the method, as was the case in your define implementation. I separated out the mixin stuff into defineMixin. I have the code living on my integration branch, which you can have a look at if you want. If this change is OK with you I'll merge it into master as well.

Thanks for the great work!

Zef

bjouhier commented 13 years ago

This change is perfectly fine. I was not too happy with the true parameter anyway.

The first implementation that I posted yesterday does not handle many to many relationships. I'm working on it. I hope to get it cracked later today.

Bruno