You can do @item.item_item_properties.each do |item_item_property| and handle that object inside the loop, I'm not sure why would you expect that item_item_properties relationship to return key, value pairs. I don't understand what you want to achieve, maybe you are trying to do it on the wrong path.
El vie., 1 nov. 2019 a las 0:27, fugee ohu (<[email protected]>) escribió: > > > On Thursday, October 31, 2019 at 9:33:22 PM UTC-4, Ariel Juodziukynas > wrote: >> >> @item.item_item_properties returns a collection of objects, you are >> calling a method on something array-like, it makes no sense. >> >> If you want to get all the item_property_ids you can >> do @item.item_item_properties.pluck(:item_property_id) for example. I'm not >> sure what you want to achieve. >> >> El jue., 31 oct. 2019 a las 22:29, fugee ohu (<[email protected]>) >> escribió: >> >>> >>> >>> On Thursday, October 31, 2019 at 2:15:48 PM UTC-4, Ariel Juodziukynas >>> wrote: >>>> >>>> Use `.size` instead of `.count`. "count" does a database query and >>>> since you only built the element the COUNT db query will return 0. "size" >>>> knows what to do if the association is already initialized so it will >>>> return "1" in your case (and if it's not already loaded it will run a COUNT >>>> db query). >>>> >>>> El jue., 31 oct. 2019 a las 8:42, fugee ohu (<[email protected]>) >>>> escribió: >>>> >>>>> > @item=Item.new >>>>> > @item.item_item_properties.build >>>>> > @item.item_item_properties.count >>>>> => 0 >>>>> >>>>> Why doesn't my @item object have any item_item_properties after build >>>>> method >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Ruby on Rails: Talk" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/rubyonrails-talk/161b90ed-b6b1-4d4d-9f67-fb70f0463621%40googlegroups.com >>>>> <https://groups.google.com/d/msgid/rubyonrails-talk/161b90ed-b6b1-4d4d-9f67-fb70f0463621%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> >>> How do I reference individual columns? >>> 2.3.3 :006 > @item.item_item_properties.item_property_id >>> NoMethodError: undefined method `item_property_id' for >>> #<ItemItemProperty::ActiveRecord_Associations_CollectionProxy:0x0055d4167fd628> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/rubyonrails-talk/a80b3961-82df-4943-9e5a-adb764d516b7%40googlegroups.com >>> <https://groups.google.com/d/msgid/rubyonrails-talk/a80b3961-82df-4943-9e5a-adb764d516b7%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> > Could I directly access key, value without pluck or otherwise like > @item.item_item_properties.each do |key, value| > item_property_id > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/b2057f01-80e0-4816-8893-b783e30159f8%40googlegroups.com > <https://groups.google.com/d/msgid/rubyonrails-talk/b2057f01-80e0-4816-8893-b783e30159f8%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcCGOC%3DindJPMT0xJGj9EmJ1c7tMLTpP00Vb1nX8wBQuUQ%40mail.gmail.com.

