-
Notifications
You must be signed in to change notification settings - Fork 312
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
Get modelName from collection when collection uses BaseModel #252
Conversation
|
Setting an |
@@ -122,7 +122,7 @@ ModelUtils.prototype.underscorize = function(name) { | |||
* MyClass.id = "MyClass" | |||
*/ | |||
ModelUtils.prototype.modelName = function(modelOrCollectionClass) { | |||
return this.underscorize(modelOrCollectionClass.id || modelOrCollectionClass.name); | |||
return this.underscorize(modelOrCollectionClass.constructor.id || modelOrCollectionClass.id || modelOrCollectionClass.collection.constructor.id || modelOrCollectionClass.constructor.name || modelOrCollectionClass.collection.constructor.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is way too long and has to much logic in it which makes it error-prone and realy hard to understand.
@@ -122,7 +122,11 @@ ModelUtils.prototype.underscorize = function(name) { | |||
* MyClass.id = "MyClass" | |||
*/ | |||
ModelUtils.prototype.modelName = function(modelOrCollectionClass) { | |||
return this.underscorize(modelOrCollectionClass.id || modelOrCollectionClass.name); | |||
var modelName = modelOrCollectionClass.constructor.id || modelOrCollectionClass.id || modelOrCollectionClass.constructor.name; | |||
if (!modelName && this.collection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean modelOrCollectionClass.collection
instead of this.collection
?
If I understand this correctly then the |
Yes, you understand this correctly. If I understand #151 correctly, this is Spike's proposed solution to I'm not sure I totally understand your question about how to reference My understanding is that But if you have a collection "Books" that doesn't specify a model, each model does not currently have a modelName. So instead of With this change, we get the modelName from the collection constructor if model.constructor.id isn't set. So in the example above, the key would be The end result is that the That said, it's still failing Travis. I'll submit a fix this weekend. |
After looking into this more, I think attempting to fix this behavior by making changes to the .modelName method isn't the best approach. I'm going to close this pull request for now and submit a new one if I make headway with a different approach. Thanks for your help @lo1tuma ! |
According to your example where I think the problem should be fixed in BTW: We should also try to refactor out all the |
When model.constructor.id isn't set (such as when a collection uses generic BaseModel), get modelName from model.collection.constructor.id.
Fixes #151