Skip to content
This repository

FastLegs include/join for multi-relationship tables/ circular dependency #38

Closed
gahula opened this Issue October 14, 2012 · 3 comments

2 participants

gahula Jan Paul Erkelens
gahula

I currently have run into two (2) roadblocks with FastLegs

  1. Joining by columns other than the primary key. How can i join two tables using other columns than the primary key? ... I may want to join a table by the author_id (not a pk) (product reviews model) and id (pk) (users model)

  2. Accessing defined models anywhere in the file, I may have to create a join for a model that comes after the model i am defining. i.e. circular dependancy ?

e.g.

USERS have many REVIEWS have many USERS (authors)

Jan Paul Erkelens

Hey. We've been quiet on this project for a while, but we're starting to try to pick up again. Hopefully we can get to this in the next week or two. Can you explain the second point about circular dependencies a little more? We typically define a model in its own file and require them, you should be able to create those dependencies that way. However, we haven't run performance tests on something like that, so I can't guarantee good results.

gahula

It is a great project, I am sure all users appreciate the effort.

circular depency (in terms of the variables) e.g.

USERS receive many reviews... REVIEWS are made by many USERS

var Reviews = FastLegS.Base.extend({
tableName: 'reviews',
primaryKey: 'id'
_fields: [
{ 'column_name': 'user_id' },
{ 'column_name': 'author_id' },
{ 'column_name': 'id' },
{ 'column_name': 'comment' }
]
});

var Users = FastLegS.Base.extend({
tableName: 'users',
primaryKey: 'id',
_fields: [
{ 'column_name': 'id' },
{ 'column_name': 'first' },
{ 'column_name': 'last' }
]
many: [
{ 'reviews': Reviews, joinOn: 'user_id' },
//**{'users': Users, joinOn: 'user_id'} Reviews may have many authors, however Users would be UNdefined (yes i know i presently wouldn't be able to connect using user_id).
]
});

If i wanted to perform a join on users and reviews; and at the sametime get the author of those reviews it would NOT be possible since (see **)

User.find({ 'id.in': ['1', '2', '3'] }, {
only: ['id', 'first', 'last'],
order: ['-first'],
include: { 'reviews': {
//** There is no way i can include users here again since i cant say
//** include on reviews.author_id = users.id
//** FastLegs always assFK to a PK OR two columns that are not Keys
}
}
}, function(err, results) {
//
});

gahula

Relationships will have to be defined outside of the models for e.g. http://nodetoolbox.com/packages/jugglingdb OR https://github.com/1602/jugglingdb they are too tightly coupled to the model.

gahula gahula closed this April 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.