On Fri, Aug 26, 2011 at 1:39 AM, Dorijan Jelincic <[email protected]> wrote:

> Hi to all,
>  have active record model that has one to many relationship. This is
> how it looks like:
>
> ruby-1.9.2-p290 :001 >
> @ukuizvj=Izvjestaj.new(:mjesec=>8, :godina=>2011,:djelatnik_id=>2)
>  => #<Izvjestaj id: nil, godina: 2011, mjesec: 8, djelatnik_id: 2,
> brojsati: nil, visak: nil, manjak: nil, nr: nil, rp: nil, komb: nil,
> created_at: nil, updated_at: nil>
>
>
> ruby-1.9.2-p290 :002 > @ukuizvj.izvjtipd
>  => []
>
>
> ruby-1.9.2-p290 :003 >
> ntiprada=Izvjtipd.new(:tipneradni_id=>1, :vrijednost=>1)
>  => #<Izvjtipd id: nil, izvjestaj_id: nil, tipneradni_id: 1,
> vrijednost: 1, created_at: nil, updated_at: nil>
>
>
>
> ruby-1.9.2-p290 :004 > @ukuizvj.izvjtipd << ntiprada
>  => [#<Izvjtipd id: nil, izvjestaj_id: nil, tipneradni_id: 1,
> vrijednost: 1, created_at: nil, updated_at: nil>]
>
>
>
> ruby-1.9.2-p290 :005 > @ukuizvj.izvjtipd
>  => [#<Izvjtipd id: nil, izvjestaj_id: nil, tipneradni_id: 1,
> vrijednost: 1, created_at: nil, updated_at: nil>]
>
> So, How can I address this value of @ukuizvj.izvjtipd? Problem is that
> @ukuizvj.izvjtipd.find_by_tipneradni_id(1).vrijednost or
> @ukuizvj.izvjtipd.where(:tipneradni_id=>1).vrijednost dont work until
> I make @ukuizvj.save
>
>
find_by_attribute and where statements both create sql statements which are
executed when you access the records.  since the record you're looking for
is not yet saved to the db, AR won't find it using these methods.


> Thank you
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>


-- 
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.com

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to