sinisterchipmunk / jax

Framework for creating rich WebGL-enabled applications using JavaScript and Ruby
http://jaxgl.com
MIT License
96 stars 16 forks source link

Model Relations #41

Open sinisterchipmunk opened 12 years ago

sinisterchipmunk commented 12 years ago

Currently, if a model is associated with another model, data must be parsed explicitly:

new SolarSystem(planets: [ { name: "mercury" }, {name: "venus" }, ... ])
// within SolarSystem#after_initialize:
for (var i = 0; i < this.planets.length; i++)
  this.planets[i] = new Planet(this.planets[i]);

It would be very helpful to establish ActiveRecord-like relations for models. Example JS:

SolarSystem.has_many "planets"
SolarSystem.has_many "planets", model_name: "Planet"
// etc.

This way, Jax could automatically convert an associated model's data into its corresponding instance.

sinisterchipmunk commented 12 years ago

A slight syntactic update to this idea. Since now we're using CoffeeScript, it's nice and clean to do things like:

class SolarSystem extends Jax.Model
  @has_many "planets"

Similar to e.g. the @include method now in master.

sinisterchipmunk commented 12 years ago

This is still going to happen, but I ran out of time for this cycle. Pushed back to v3.1.