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

Use collectionName for ModelStore key when modelName isn't set #253

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Use collectionName for ModelStore key when modelName isn't set #253

wants to merge 4 commits into from

Conversation

shebson
Copy link
Contributor

@shebson shebson commented Jan 6, 2014

When a model does not have a modelName and belongs to collection that is named, use the collectionName in place of the modelName when generating the ModelStore key.

Fixes #151. cc @lo1tuma

@@ -121,7 +129,7 @@ ModelUtils.prototype.underscorize = function(name) {
* -> ""
* MyClass.id = "MyClass"
*/
ModelUtils.prototype.modelName = function(modelOrCollectionClass) {
ModelUtils.prototype.modelOrCollectionName = function(modelOrCollectionClass) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can find a less verbose name for this? Perhaps we could use resource instead of modelOrCollection?

Copy link
Member

Choose a reason for hiding this comment

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

It actually describes exactly what the method does. I think the problem here is not the name but rather doing two things at once.

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 absolutely agree that modelOrCollectionName is unwieldy. I chose it for consistency with modelOrCollection, a variable which is used in the fetcher and view engine, but I agree that resourceName is better.

I think that this is just a naming issue, though, and not a problem of trying to do two things in one method. This method takes a constructor and returns its underscorized id. I see that as one task with multiple applications.

@spikebrehm
Copy link
Member

Thanks @shebson, this is an elegant way to solve this problem. The renaming to getModelOrCollectionName and associated variables seems a little unnecessary, or at least the name is very long. Something better?

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.

Fix blank modelName when collection uses generic BaseModel
3 participants