lines = FasterCSV.read(Rails.root.join(''public'',
''data'', ''negozi.csv''))
lines.slice!(0)
lines.each do |row|
if row.any?
begin
role_date = Date.strptime("#{row[4]}", "%d/%m/%Y")
reference_date = Date.strptime("#{row[6]}",
"%d/%m/%Y")
rescue
reference_date = role_date = nil # se la data non e'' valida
inserisci un valore nullo
end
shop = Shop.create!(:role_number => row[3], :role_date =>
role_date, :name => row[7], :ssn => row[8],
:nationality => row[9], :address => "#{row[10]}
#{row[11]}", :street_number => row[12],
:website => row[24], :district => row[13], :sector =>
row[15],
:square_meters => row[16], :state => row[2],
:notes => row[22])
shop.documents.create!(:reference_number => row[5],
:reference_date => reference_date,
:subject => row[14])
rake db:seed
Then I open console: rails c and I do
shop=Shop.where(:role_number => ''5'')
shop.documents
I have method missing documents error.
Why?
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Shop has_many :documents and Document belongs_to :shop -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thursday, May 5, 2011 3:19:33 PM UTC-4, mauro wrote:> > shop=Shop.where(:role_number => ''5'') > shop.documents > I have method missing documents error. > Why? >Are you sure that Shop.where(:role_number => ''5'') is returning only one record? What''s the output of this: puts Shop.where(:role_number => ''5'').class -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 May 2011 21:25, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote:> On Thursday, May 5, 2011 3:19:33 PM UTC-4, mauro wrote: >> >> shop=Shop.where(:role_number => ''5'') >> shop.documents >> I have method missing documents error. >> Why? > > Are you sure that Shop.where(:role_number => ''5'') is returning only one > record? > > What''s the output of this: > > puts Shop.where(:role_number => ''5'').classActiveRecord::Relation> > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Actually, it doesn''t matter. I just rememebred where() is always going to return and ActiveRecord::Relation instance, *not* an instance of your model. You''ll need to access one of the model instances to be able to see the documents: shops = Shop.where(:role_number => ''5'') shops[0].documents -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 May 2011 21:28, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote:> Actually, it doesn''t matter. I just rememebred where() is always going to > return and ActiveRecord::Relation instance, not an instance of your model. > > You''ll need to access one of the model instances to be able to see the > documents: > > shops = Shop.where(:role_number => ''5'') > shops[0].documentsAh ok. shop=Shop.find_by_role_number(5) now shop.documents works. 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.