ufront / ufront-orm

The Object Relational Mapper, allows easy, type-safe access to your database. Builds on Haxe's SPOD but adds macro powered relationships, validation and client side usage
MIT License
13 stars 4 forks source link

[Feature Request] Aliases for fields #27

Open grisevg opened 9 years ago

grisevg commented 9 years ago

Hi,

I'm trying to use the orm with already existing rails database, but the orm uses created and modified fields instead of rails ones created_at and updated_at.

It would be very useful to be able to make the orm use different database field names from haxe field names. Maybe something like:

manager.aliases.set("created", "created_at");
manager.aliases.set("modified", "updated_at");

or even a compile time macro

@aliases("created"="created_at", "modified"="updated_at")
class MyModel extends Object {}

What do you think?

jasononeil commented 8 years ago

I like the idea (and it would be useful to have Haxe code interact with a rails database, as you mention) but have no idea how to implement it, short of replacing the entire sys.db.RecordMacros with our own implementation...

jasononeil commented 8 years ago

Two options:

  1. Patch the standard library (or spod haxelib if these classes get moved to a haxelib) to support this.
  2. Create a subclass of Manager that uses our own macros when we need to do things differently
  3. Have a ufront.db.BaseObject, that has the basic Ufront additions (serialization, save() etc), but skips the included fields (id, modified, created). This would mean these tables wouldn't support our join relationships now though, at least until we add better support for custom IDs.

I'm going to leave the issue open but not sure when I'll get to it, it's quite a complex issue to solve sadly :(

kevinresol commented 8 years ago

Patching the std lib is easier, indeed we can open an issue on the Haxe repo... I also wanted such feature when I want to use haxe keywords as db field name (e.g. class)

jasononeil commented 8 years ago

Okay, I agree: patching the standard library sounds the smartest (and probably easiest)

I just know Simon will want to close the issue because he wants all the sys.db.* classes moved to a separate haxelib. I'll keep this issue open until we create a different issue :)