ghostrifle
2007-Oct-07  08:52 UTC
activerecord problem with contrains,belongs_to and has_many keyword
Hi,
I have two models:
AdvertisementImages (table: advertisement_images)
Advertisement (table: advertisements)
The table advertisement_images has a foreign key to advertisements
called advertisement_id. Both tables has one entry where the entry in
dvertisement_images belongs to advertisement.
The model code looks lik this so far:
class AdvertisementImages < ActiveRecord::Base
  file_column :image
  belongs_to :advertisement
end
class Advertisement < ActiveRecord::Base
  has_many :advertisementimage
  validates_presence_of :title, :body
end
Well... I want now have access to the advertisement images where ever
I display an advertisement.
for example:
I have a view where I can edit an advertisment. In this view I wanna
display the images as well.. My problem is, that the advertisement
doesn''t fetch the images automatically.
When I dump the advertisement via <%= debug @advertisement %>, my
output is :
--- &id001 !ruby/object:Advertisement
attributes:
  valid_to: "2007-10-06"
  body: some text
  title: Villa Katherina
  service:
  id: "1"
  valid_from: "2007-10-06"
  active: "0"
  parent:
errors: !ruby/object:ActiveRecord::Errors
  base: *id001
  errors: {}
I must have done a mistake somewhere in my declarations or so.... does
anyone know what I''ve done wrong ??
Thanx in advance,
alex !
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Alexander Bierbrauer
2007-Oct-07  09:57 UTC
Re: activerecord problem with contrains,belongs_to and has_many keyword
Hi, well I found my error. I named the image model AdvertisementImages instead of AdvertisementImage. Changing the name solved my problem. Thanx for the guy in the irc channel for helping me out ! Bye, Alex --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---