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 (<fugee...@gmail.com>) 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 rubyonrails-talk+unsubscr...@googlegroups.com.
> 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>
> .
>

-- 
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 rubyonrails-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcC%3Djx6MabXASiB2DXgNMeWdw0TMo%2B%3D979RgfHnoN-rH_Q%40mail.gmail.com.

Reply via email to