Skip to content

Public model_name_for_type method#924

Merged
lgebhardt merged 2 commits intoJSONAPI-Resources:masterfrom
Exelord:feature-real-name-model
Dec 8, 2016
Merged

Public model_name_for_type method#924
lgebhardt merged 2 commits intoJSONAPI-Resources:masterfrom
Exelord:feature-real-name-model

Conversation

@Exelord
Copy link
Copy Markdown
Contributor

@Exelord Exelord commented Dec 8, 2016

Hi,
I just think this method could be used in many cases associated with polymorphic relations like filtering by polymorphic model type. In that case having this public could make it easier to implement.

@lgebhardt
Copy link
Copy Markdown
Contributor

@Exelord Looking at it a little closer the method should probably be a class method and moved down to the self section. I should have caught that in #882. How about renaming it to something closer to resource_type_for, which is it's reciprocal, such as model_name_for_type or just model_name_for.

  class << self
  #...
      def model_name_for_type(type)
        type_class_name = type.to_s.classify
        resource = resource_for(type_class_name)
        resource ? resource._model_name.to_s : type_class_name
      end
  end

@Exelord
Copy link
Copy Markdown
Contributor Author

Exelord commented Dec 8, 2016

@lgebhardt You are right! I just forgot about moving it to self. I applied your feedback with method name and fixed tests :)

If u have more ideas or comment, go on!

Thanks :)

@lgebhardt lgebhardt changed the title Public real_model_name method Public model_name_for_type method Dec 8, 2016
@lgebhardt lgebhardt merged commit f5f8444 into JSONAPI-Resources:master Dec 8, 2016
@lgebhardt
Copy link
Copy Markdown
Contributor

@Exelord Thanks!

@Exelord Exelord deleted the feature-real-name-model branch December 8, 2016 20:50
@toobulkeh
Copy link
Copy Markdown

toobulkeh commented Mar 2, 2017

How can this new feature be used?

Trying to see if it's something that can temporarily be used for #927

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.

3 participants