-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
ColumnName in the association primaryKey #6144
Comments
+1 I'm hitting this issue also. Specifying pk = self._context._attributes[key].columnName || key; There's more to the problem that I cannot find the root cause to though. The joins are also not using columnName for primaryKey in child relationships. For example, the criteria passed to query/finders/basic.js#findOne includes the model key name (id) and not columnName (people_id) for "childKey" in the joins list. You should be able to reproduce the issue with these models using any adapter: // One Account can have many Tickets
// One ticket can have many TicketComments
//
// When you try to run `Ticket.find().populate('account').populate('comments')`
// the population will for both the Ticket's child relationship to Account, and
// for the Ticket's parent relationship to TicketComment.
// Account -------------------------------------------------------------------
attributes: {
id: {
columnName: 'account_id',
type: 'string',
primaryKey: true
},
name: 'string',
////////////////////////
// Associations
tickets: {
collection: 'Ticket',
via: 'account'
}
}
// Ticket --------------------------------------------------------------------
attributes: {
id: {
type: 'string',
columnName: 'ticket_id',
primaryKey: true
},
ticketNumber: 'string',
////////////////////////
// Associations
account: {
type: 'string',
columnName: 'account_id',
model: 'Account'
}
comments: {
collection: 'TicketComment',
via: 'ticket'
},
}
// TicketComment -------------------------------------------------------------
attributes: {
id: {
type: 'string',
columnName: 'comment_id',
primaryKey: true
},
commentBody: 'string',
////////////////////////
// Associations
ticket: {
type: 'string',
columnName: 'parent_ticket_id',
model: 'ticket'
}
} |
Thanks @jasonsims I'll take a look |
I've tried to debug this problem. I came to the line https://github.com/balderdashy/waterline/blob/master/lib/waterline/query/deferred.js#L121 where
Where the attr.on is come from? I didn't find were this is filled. I think @jasonsims isn't correct with the line https://github.com/balderdashy/waterline/blob/master/lib/waterline/query/deferred.js#L83 because on the line https://github.com/balderdashy/waterline/blob/master/lib/waterline/query/deferred.js#L119 there is what he suggest.
|
@Mordred deferred.js#L119 There's a separate issue going on which you mentioned with |
Sorry, you are right |
Ok guys finally had some time to dig into this and pushed out a fix to Waterline with the PK fix (thanks @jasonsims ) and a patch to Waterline-Schema to fix the Using the schema above I tested it and it seems to be good. Would you guys mind pulling down the changes and giving it a go? |
Sorry for the delay! I got some time to test your fixes out today and it seems partially fixed. The columnName attribute on primary key isn't fully ignored anymore but I'm still seeing an issue with one-to-many relationships. For example, from the schema above, one ticket can have many comments. For some reason the server is returning all items from the many side of the op but when waterline integrates the results, all but one of the items are dropped. // Expected
{
id: 1234,
ticketNumber: "0000013",
comments: [
{id: 582834, ticket: 1234, commentBody: "Comment #1"},
{id: 822242, ticket: 1234, commentBody: "Comment #2"},
{id: 682499, ticket: 1234, commentBody: "Comment #3"}
}
// Actual
{
id: 1234,
ticketNumber: "0000013",
comments: [
{id: 582834, ticket: 1234, commentBody: "Comment #1"}
} @particlebanana did you also test the fix against this one-to-many scenario? The schema above defines the relationship as one-to-many but unless there were multiple objects in the datastore on the many side, this particular issue wouldn't present itself. |
Ok @jasonsims just pushed up another fix. Tested it with your data schema and it works. Let me know if you see any more issues. |
Nice, all is well now. @particlebanana do you know approximately when this will make it into the next RC? |
I can publish it tomorrow after giving the issues another run through. |
Ok @jasonsims this is published to npm as |
Hi,
I'm trying to map sails models to the very old database tables:
But I'm getting an error:
I think that the columnName of the Person.attributes.id is not used.
I don't know if this is waterline problem or sails-mysql. I'm using a sails-mysql 0.10.0-rc5
The text was updated successfully, but these errors were encountered: