Hi,
Here is my model:
- One Card has one or many Graphs
- One Graph is related to one and only one Card
// Define a new table
Card = persistence.define('Card', {
remote_id: "INT",
name: "TEXT",
description: "TEXT",
graph_count: "INT"
});
Card.index(['remote_id'], {unique:true});
Graph = persistence.define('Graph', {
remote_id: "INT",
name: "TEXT",
description: "TEXT",
type:"TEXT"
});
Graph.index(['remote_id'], {unique:true});
Card.hasMany('graphs', Graph, 'card');
I would like to fetch a Card by its id and retrieve all its Graphs at the same time?
First, I tried this:
Graph.all().prefetch("card").filter("card", '=', steroids.view.params.id).list(function(graphs) {
console.log("==============> FOUND: "+graphs[0].card.name+" graphs:"+JSON.stringify(graphs));
$scope.loading = false;
steroids.view.navigationBar.show(card.name);
$scope.$apply();
});
But it always return only one Graph per card even if I have many related to this Card.
Then, I tried this:
Card.all().filter("id", '=', steroids.view.params.id).prefetch("graphs").list(function(cards) {
console.log("==============> Found: "+JSON.stringify(cards));
});
But the query is not fired, nothing happens!
Any solution?
Thanks.