Just to be clear, the library I have been working on under the working title ThyncRecord I’ve now re-dubbed JazzRecord.
JazzRecord.org is now up, with a working, not quite up-to-date version of the library to work with. There’s also a live demo for tooling around w/ Gears, JazzRecord, and Firebug.
We will be switching to Github soonish, and will probably link there directly for the nightly copy. We’ve still got to work out our versioning/release process.
As well, we’ve made several changes of note since I last blogged:
- Validation is solid: The previous concept of having a single
validate()method has been replaced with three optional methods:
validateAtSave(). These are run prior to initial record insertion or updating respectively for the first two, and on any save for the last. Almost all ActiveRecord validation methods have been ported over for use in these user-defined methods.
The Record.errors array contains any errors generated during the save process, or a direct call to
Improper data is coerced into the correct type prior to saving the record, as in ActiveRecord. What this means is that, though the data might not be meaningful, it is at least valid in terms of the schema.
We’ve begun adding support for “dirty records” and will be supporting a good portion of the Rails 2.1 capabilities in this vein.
Autolinking and unlinking of associations is coming along. So far, hasOne and belongsTo associations are supported. We hope to have all 4 association types supported within a week.
Basically, you can assign a record object directly to the named association property of a base record, and when the base record is saved it will rewrite its foreign key with the ID of the newly-associated record. It also works the other way round (assigning the foreign key property manually will cause the associated record to load after saving the base record).
Taking it one step further, if you reassign a hasOne relationship so that it points to a new record, the original record which belonged to the base record will have its foreign key deleted and the new record will have it assigned in its place.
Similarly, deleting a named association property (or, again, the associated foreign key) or setting it to null will unlink the two records by whichever means is necessary, given the association type. For instance, in a belongsTo relationship, the record which belongs to another record will have its foreign key deleted.
The hasMany and hasAndBelongsToMany association types will soon behave as expected, but a little more infrastructure needs to be added before hasMany will work. Removing an item from the array of “many” returned for the associated collection of records will cause that record’s foreign key (corresponding to the base record’s ID) to be deleted.
- Have begun writing automated test scripts using JSSpec, and will be building them out extensively over the next few days so we can truly claim it’s been tested and is solid.
This all goes a long way to making JazzRecord closer to being feature-complete and ready for action.