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

wrong belongsTo behavior when using with postgresql #57

Closed
tanqhnguyen opened this issue Apr 7, 2012 · 2 comments
Closed

wrong belongsTo behavior when using with postgresql #57

tanqhnguyen opened this issue Apr 7, 2012 · 2 comments

Comments

@tanqhnguyen
Copy link

I have this schema definition

var Domain = schema.define('domain', {
  name: Number
});

var User = schema.define('user', {
  email: String
});

Domain.belongsTo(User, {as: 'user', foreignKey : 'user_id'});
User.hasMany(Domain, {as : 'domains', foreignKey: 'user_id'});

Then I created some domains and add them to a particular user. I have checked the database and everything is ok.

Then, I do

domain.user(); // It can get the user id

However if I do something like this

domain.user(function(error, user){
  // user should be a user record ?
});

I got this error

TypeError: Object #<Object> has no method 'find'
    at Object.domain (/home/vagrant/lib/node_modules/jugglingdb/lib/abstract-class.js:690:22)
    at ModelConstructor.domain (/home/vagrant/lib/node_modules/jugglingdb/lib/abstract-class.js:705:40)

I am using postgresql 9.1 on Ubuntu 11.10.

@anatoliychakkaev
Copy link
Collaborator

This error may happen when User is not defined correctly before calling
Domain.belongsTo. What if move relationships defenitions to proper place?
(I mead app/models/ dir)

BTW, model names should start with upper case letter.

On Sat, Apr 7, 2012 at 10:15 AM, laoshanlung <
reply@reply.github.com

wrote:

I have this schema definition

var Domain = schema.define('domain', {
 name: Number
});

var User = schema.define('user', {
 email: String
});

Domain.belongsTo(User, {as: 'user', foreignKey : 'user_id'});
User.hasMany(Domain, {as : 'domains', foreignKey: 'user_id'});

Then I created some domains and add them to a particular user. I have
checked the database and everything is ok.

Then, I do

domain.user(); // It can get the user id

However if I do something like this

domain.user(function(error, user){
 // user should be a user record ?
});

I got this error

TypeError: Object #<Object> has no method 'find'
   at Object.domain
(/home/vagrant/lib/node_modules/jugglingdb/lib/abstract-class.js:690:22)
   at ModelConstructor.domain
(/home/vagrant/lib/node_modules/jugglingdb/lib/abstract-class.js:705:40)

I am using postgresql 9.1 on Ubuntu 11.10.


Reply to this email directly or view it on GitHub:
#57

Cheers,
Anatoliy Chakkaev
web-developer [js, rails, php]
+7.917.857.858.4

@tanqhnguyen
Copy link
Author

Yes, I have just figured it out. I define models in separated files, which cause errors when models are related to each other. I have moved the relationship definition to a different file and call that file after all models are defined. It works now.

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