Rails 4.1 enum query -



Rails 4.1 enum query -

i seeing rails generate wrong query value when utilize enum col value in clause, (self added clarity). dominant_product_strategy enum.

def some_model_method_on_mymodel mymodel.where(dominant_product_strategy: self.dominant_product_strategy) end

this produces right value (again, self added clarity):

mymodel.where(dominant_product_strategy: self.attributes["dominant_product_strategy"])

i'm guessing rails sees enum string, , converts integer value of zero. ughhhhh!

am missing something?

this works:

mymodelwhere(dominant_product_strategy: mymodel.dominant_product_strategies[dominant_product_strategy])

it seems have answered question yoursef. enum variables hash:

{str1: int1, str2: int2, ...}

the value (integer) storing in db, , string representation of int value. when phone call self.dominant_product_strategy, representation (string) of dominant_product_strategy column storing integer in db.

i think first working solution (self.attributes["dominant_product_strategy"]) fine.

ruby-on-rails

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -