Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapsTo don't map when chaining methods #530

Closed
PymZoR opened this issue Jul 10, 2014 · 1 comment
Closed

mapsTo don't map when chaining methods #530

PymZoR opened this issue Jul 10, 2014 · 1 comment

Comments

@PymZoR
Copy link

PymZoR commented Jul 10, 2014

Hi,
as the title is relevant enough, this is how I produced the bug:

    var Fundation = db.define('fundation', 
        {
            id: { 
                mapsTo: 'fun_id',
                type: 'serial', 
                key: true 
            }, 

            name: { 
                mapsTo: 'fun_name',
                type: 'text', 
                size: 40  
            },

            removed: { 
                mapsTo: 'fun_removed',
                type: 'boolean',
                defaultValue: false 
            }
        }, 


        {
            collection: 't_fundation_fun',
            validations: {
                name: [
                    orm.enforce.unique('Name already taken.'),
                    orm.enforce.notEmptyString('Fundation must have name.')
                ],
            }
        }
    );  // model Fundation
    Fundation.find({ name: 'thisIsATest' }).remove(function(err) {
        console.log(err);
        done();
     }); // test

Will produce with the debug flag:

(orm/mysql) SELECT * FROM t_fundation_fun WHERE name = 'thisIsATest'
{ [Error: ER_BAD_FIELD_ERROR: Unknown column 'name' in 'where clause']
code: 'ER_BAD_FIELD_ERROR',
errno: 1054,
sqlState: '42S22',
index: 0 }

However, if I change the test code to:

        Fundation.one({ name: 'thisIsATest' }, function(err, testFundation) {
            testFundation.remove(function(err) {
                console.log(err);
                assert.equal(err, null);
            });
        });

Will produce the correct SQL for the find:

(orm/mysql) SELECT fun_id, fun_name, fun_removed FROM t_fundation_fun >WHERE >fun_name = 'thisIsATest'

But not for the delete ! (it should be fun_id, not id)

(orm/mysql) DELETE FROM t_fundation_fun WHERE id = 3

It seems like chaining find doesn't work weel with mapsTo, as well for using the delete method

@dxg dxg closed this as completed in f4dd197 Aug 21, 2014
@dxg
Copy link
Collaborator

dxg commented Aug 21, 2014

Fixed & published in ORM 2.1.19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants