views:

184

answers:

1

I have a problem with associations. As a newbie to RoR, I've learned about associations from the guide on the RoR site. I have followed one of the example almost to the letter, the only thing being changed are the class names. The example being the following:

class Document < ActiveRecord::Base 
  has_many :sections  
  has_many :paragraphs, :through => :sections 
end 

class Section < ActiveRecord::Base 
  belongs_to :document
  has_many :paragraphs 
end 

class Paragraph < ActiveRecord::Base 
  belongs_to :section 
end

In my project, its Wizard, Page and Fields instead of Document, Section and Paragraph. In addition to following this example, I'm also using Typus as an admin interface. Everything appeared to be working fine. I created a wizard. Then created a page from the wizard section. Once I tried creating a field to be associated with a page it produced an error:

ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection in Admin/fieldsController#create

Cannot modify association 'Wizard#fields' because the source reflection class 'Field' is associated to 'Page' via :has_many.

. Unfortunately (and it may be my search terms) google doesn't seem to turn anything up that appears to be helpful to me. Does anyone have any advice on how to get this to work? Sorry in advance if I didn't state everything clearly.

A: 

Perhaps you tried to add a field from the Wizard section instead of from the Page section? That won't work because it has to know which page to add the field to.

mckeed
Sorry, I should have clarified that typus will add a drop down box showing existing pages associated with the current wizard. So if there is a wizard named test_wizard, I can associate a page (named test_page for example) with it. But once I try to associate a field (we'll use test_field) with it, everything falls apart. test_wizard will show test_page with it. It will even show test_field when I create it directly from the Fields admin section and associate it with test_page. But if I try to create it from within test_wizard (using the same exact procedure I did with test_page) it fails
BigForNothing
Yes, that is what I meant. The way you have it set up, fields are not directly associated with wizards. The only way to associate a field with a wizard is to associate it with a page that is associated with the wizard.
mckeed