Silicon-Age / opal

Silicon Age's ORM layer.
0 stars 0 forks source link

Allow partial static bindings in the Factories #9

Open jonahgreenthal opened 1 year ago

jonahgreenthal commented 1 year ago

There are some classes in which some rows are "special" and need to be statically bound to, but most rows are not. In the NAQT project, for example, we often needed the special Org rows for "None" and "NAQT", but we certainly wouldn't want to generate static bindings for all the tens of thousands of Orgs.

This can be faked by adding to the UserFacing-subinterface (e.g., Org.java) something like this:

public static Org NONE() {return OrgFactory.getInstance().forId(1);}

but writing that manually is inelegant. It would be cool if Opal could be given a query and a column, e.g.,

<Mapping Table="Org">
    <StaticBindings Query="id < 1000" FieldNamesFrom="short_name" />
    …
</Mapping>

(the latter attribute meaning "use the short_name column as the source for the static method name", since Org doesn't have a code column).