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

Fix for issues #622 & #623 #626

Merged
merged 2 commits into from
Jun 16, 2015

Conversation

ningsuhen
Copy link
Contributor

Fix for issues #622 & #623

polymorphic hasOne needs separate handling and hasMany->referencesMany has a unique case which is fixed for MongoDB as suggested by @fabien.

polymorphic hasOne needs separate handling and hasMany->referencesMany has a unique case which is fixed for MongoDB as suggested by @fabien.
@raymondfeng
Copy link
Contributor

LGTM. @fabien Please review.

async.each(targets, linkOneToOne, next);
function linkOneToOne(target, next) {
var sourceId = target[relation.keyTo];
var obj = objIdMap[sourceId.toString()];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should check that obj is actually defined at this stage (defensive coding ...)? There are probably other parts of this code where this might be appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it makes sense only for the referencesMany -> hasMany case because it is possible to have no value for a map key. In other cases, it should always have a map entry.

@fabien
Copy link
Contributor

fabien commented Jun 11, 2015

@raymondfeng other than the comment, LGTM

@raymondfeng
Copy link
Contributor

@ningsuhen Can you address the comment from @fabien so that we can merge the PR?

@ningsuhen
Copy link
Contributor Author

@raymondfeng , I had replied to the comment. I think it is applicable only in case of referencesMany <-> hasMany because target[relation.keyTo] can be an Array of ObjectIds instead of an ObjectId. Even if there are other cases where it can be an array, we need to handle it as an array apart from just null checking. Is there any other case where referencesMany can be used in conjunction with another relation?

@fabien
Copy link
Contributor

fabien commented Jun 16, 2015

@raymondfeng LGTM

@ningsuhen
Copy link
Contributor Author

@fabien, @raymondfeng , I have added the checks anyway :).

raymondfeng added a commit that referenced this pull request Jun 16, 2015
@raymondfeng raymondfeng merged commit bbe9cb3 into loopbackio:master Jun 16, 2015
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

Successfully merging this pull request may close these issues.

4 participants