0

I'm re-writing an existing application from WebSql to JayData. The app is built on WebSql which, being, depricated, needs to be replaced (sooner or later at least). I re factored all the WebSql into its own Adapter and am now attempting to write a parallel adapter using JayData.

What I want to know is how to gracefully handle a sql join. Here's an example

read: function (display) {
    var sql = "",
        args = [];

    sql += "SELECT table1.table1Id, table1.name, table1Local.UpdateTime ";
    sql += "FROM table1";
    sql += "LEFT OUTER JOIN table1Local ON table1.table1Id = table1Local.table1Id ";
    sql += "WHERE table1Local.Display = ? ";

    args[0] = (display === true ? "1" : "0");

    return database.read(sql, args);
},

I have two jayData entities "table1" and "table1Local" inside a context. This is my rough cut attempt but it doesn't join the data.

   read: function (display) {

        display = display === true ? "1" : "0";

        var dfd = $.Deferred();

        var context = new Table1Context({
            name: config.database.type,
            databaseName: config.database.name
        });

        context.onReady(function(){

            return context.Table1
                .filter(function( t){
                    // We need to use the Display property in the local "table"
                    return t.display == this.display;
                }, {display: display})
                .toArray()
                .then(function (ts) {

                        var data= [];

                        ts.forEach( function(t) {
                            data.push(t);
                        });

                        dfd.resolve(data);
                        return views;
                    });
        });

        return dfd.promise();
    }

I'm a little lost about how make this work properly.

Jon Wells
  • 4,191
  • 9
  • 40
  • 69

1 Answers1

0

I guess you have two entitysets in the Table1Context and two entity definitions, the two entity definitions reference each other. In this case you can change the code of the filter() to

t.table1local.display == this.display;
Robesz
  • 1,646
  • 11
  • 13