martijndeh/fire

Calculated properties

arjan123 opened this issue · 2 comments

Hi,

Due to busy times I didn't had the opportunity to dive in nodeonfire but now I'm back on track again...
I was looking into the virtual and readonly properties and I was wondering if it is possible to create a read-only property based on related objects?

thx
Arjan

Currently this is possible through PropertyTypes#Has. It's not documented yet as the name is going to change to something more suiting.

You can do something like:

function Project() {
    this.tasks = [this.Has(function(TaskModel) {
        return TaskModel.find();
    })];
}
app.model(Project);

function Task() {
    this.name = [this.String, this.Required];
}
app.model(Task);

This creates a Project#getTasks method in the client-side which you can call on project instances.

Is this something you're looking for?

I'm assuming this can be closed. Please let me know if there is something else.