Hi,

> DIDN'T WORK:
>   belongs_to :recipe
>   belongs_to :category
> 
> WORKED:
>   belongs_to :category
>   belongs_to :recipe

I just found that the same fact separately :-)

I noticed that there are circular dependencies between models.
Viewhint declarations needs complete reflections about related models
but it may not be solved if the viewhint is declared in a model class
and there are circular dependencies between models.

For example using four_table:

  % git clone [email protected]:BI/RapidRails3ForHoboTutorialSourceCode.git
  % cd RapidRails3ForHoboTutorialSourceCode/four_table 
  % rake db:migrate --trace 2>&1 | grep -C2 app/models                        
  /var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/view_hints.rb:17:in 
`block in setter'
  /var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model.rb:340:in `children'
  
/tmp/RapidRails3ForHoboTutorialSourceCode/four_table/app/models/category.rb:13:in
 `<class:Category>'
  
/tmp/RapidRails3ForHoboTutorialSourceCode/four_table/app/models/category.rb:1:in
 `<top (required)>'
  
/var/lib/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in
 `load'
  
/var/lib/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in
 `block in load_file'
  --
  /var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model.rb:180:in 
`belongs_to_with_test_methods'
  
/var/lib/gems/1.9.1/gems/hobo_fields-1.3.0.pre25/lib/hobo_fields/model.rb:93:in 
`belongs_to_with_field_declarations'
  
/tmp/RapidRails3ForHoboTutorialSourceCode/four_table/app/models/category_assignment.rb:9:in
 `<class:CategoryAssignment>'
  
/tmp/RapidRails3ForHoboTutorialSourceCode/four_table/app/models/category_assignment.rb:1:in
 `<top (required)>'
  
/var/lib/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in
 `load'
  
/var/lib/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in
 `block in load_file'
  --
  /var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/view_hints.rb:17:in 
`block in setter'
  /var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model.rb:340:in `children'
  
/tmp/RapidRails3ForHoboTutorialSourceCode/four_table/app/models/recipe.rb:19:in 
`<class:Recipe>'
  
/tmp/RapidRails3ForHoboTutorialSourceCode/four_table/app/models/recipe.rb:1:in 
`<top (required)>'
  
/var/lib/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in
 `load'
  
/var/lib/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in
 `block in load_file'
  --
  /var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/view_hints.rb:17:in 
`block in setter'
  /var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model.rb:340:in `children'
  
/tmp/RapidRails3ForHoboTutorialSourceCode/four_table/app/models/country.rb:12:in
 `<class:Country>'
  
/tmp/RapidRails3ForHoboTutorialSourceCode/four_table/app/models/country.rb:1:in 
`<top (required)>'
  
/var/lib/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in
 `load'
  
/var/lib/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in
 `block in load_file'

*

  - First, Country is loaded.

  - In Country, "children :recipes" initiates loading Recipe.

  - In Recipe, "children :categories" loads CategoryAssignment.

  - In CategoryAssignment, "belongs_to :category" loads Category.  At
    this point, "belongs_to :recipe" is not evaluated yet.

  - In Category, "children :recipes" doesn't initiate loading Recipe,
    because it is already (at least partially) loaded.  Instead, it
    continues to do real "children" job.  It extracts
    source_reflection from through_reflection, but "belongs_to
    :recipe" had not evaluated yet, so the source_reflection will be
    nil and cause "undefined method `class_name' for nil:NilClass".

There's a workaround.  Use the traditional way: move the viewhints
into separate files in app/viewhints.

-----
Tomoaki Hayasaka <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" 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/hobousers?hl=en.

Reply via email to