ruby on rails - Convert a Activerecord result with has_one associations into a single hash per record -


If I have any results from the Active Records, then I have an array of hashes, if I have a reliable load, then every Each organization hash in record hash has a nested hash of its associated records

My question is, is there a quick rail system that allows you to merge these nested hashes into a hash per record?

An analogy will be changing the records table rows

Another resemblance will be converted into a hash at one level of nested hashes.

approach 1:

select them in the section Include

  class user has_one: profile end is for square profile: user # street 1, street 2, city etc. end profile = profile.junks (user :). Selection ("User. *, Profile. *") All profiles. First.login   

Approach 2:

Use delegation

  for class profiles : User # Street 1, Road 2, City etc. Representative: Name ,: name =,: email,: email = ,: from = to & gt; : End of user    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -