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

Model for hasOne foreign key issues #75

Open
zorrofox opened this issue May 25, 2013 · 0 comments
Open

Model for hasOne foreign key issues #75

zorrofox opened this issue May 25, 2013 · 0 comments

Comments

@zorrofox
Copy link
Contributor

I have one table employee have one foreign key with other table department, and the table column and data below:
For empoyee

employee_idemployee_namedepartment_id
1Tom Preston-Werner1
2Albert Einstein1

For department

department_iddepartment_name
1Department1
2Department2

I have this model define and query below:

...
department = persist.define('department', {
    'id' : {
        type : type.INTEGER,
        dbColumnName : 'department_id',
        primaryKey : true
    },
    'department_name' : type.STRING
});

employee = persist.define('employee', {
    'id' : {
        type : type.INTEGER,
        dbColumnName : 'employee_id',
        primaryKey : true
    },
    'employee_name' : type.STRING
}).hasOne(department);

persist.connect({
    "driver" : "oracle",
    "hostname" : "localhost",
    "user" : "hr",
    "password" : "welcome1",
    trace : true
}, function(err, connection) {
    employee.include('department').all(connection, function(err, employees) {
        if(err)
              console.log(err);     
    });

});
...

But the ORM will return this SQL to me:

select t0.employee_id AS c0,
 t0.employee_name AS c1,
 t0.department_id AS c2,
 t1.department_id AS c3,
 t1.department_name AS c4 
FROM employees t0 
LEFT JOIN departments t1 ON t1.employee_id=t0.department_id  

It is very stange the ORM will use the employee_id as the join key. Anyone also has this issue?

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

1 participant