vidigami / backbone-sql

PostgreSQL, MySQL, and SQLite3 storage for BackboneORM
http://vidigami.github.io/backbone-orm/backbone-sql.html
MIT License
14 stars 8 forks source link

Paging broken when performing a join, when the table has a column with the same name as one of related table's columns #6

Open forivall opened 10 years ago

forivall commented 10 years ago

Prototype of a possible test case:

class A extends Backbone.Model
  schema:
    b: -> ['belongsTo', B]
    c: -> ['belongsTo', C]
  sync: require('backbone-sql').sync(A)
  url: 'postgres://test:test@127.0.0.1:3306/test/as'

class B extends Backbone.Model
  schema:
    name: 'String'
    as: -> ['hasMany', B]
    c: -> ['belongsTo', C]
  sync: require('backbone-sql').sync(B)
  url: 'postgres://test:test@127.0.0.1:3306/test/bs'

class C extends Backbone.Model
  schema:
    memberships: -> ['hasMany', A]
    roles: -> ['hasMany', B]
  sync: require('backbone-sql').sync(C)
  url: 'postgres://test:test@127.0.0.1:3306/test/cs'

A.cursor({$page: true, $offset:0, $limit:150, c_id:12}) # works fine
A.cursor({$page: true, $offset:0, $limit:150, c_id:12, 'b.name': 'foo'}) # fails
# Error: column reference "c_id" is ambiguous, sql: select count(*) from "as" left outer join "roles" on "as"."b_id" = "b"."id" where "c_id" = ? and "b"."name" = ?, bindings: 12,foo
A.cursor({$page: true, $offset:0, $limit:150, 'b.c_id':12, 'b.name': 'foo'}) # works; but suboptimal