I think my problem was that I was using add_link instead of add_scoped_link.
With add_scoped_link, it looks like it is better. however, now it is doing
something I completely can't figure out:
The SQL generated for my images (which is the child table of course) has
correct clauses for viewable_id and viewable_type, but it also has an ORDER BY
`products`.`created_at` (products is my parent table).
Mysql2::Error: Unknown column 'products.created_at' in 'order clause': SELECT
`assets`.* FROM `assets` WHERE `assets`.`type` IN ('Image') AND
`assets`.`viewable_id` = 1064 AND `assets`.`viewable_type` = 'Product' ORDER BY
`products`.`created_at` DESC LIMIT 15 OFFSET 0
(emphasis added by me of course)
This hiccups because the SELECT statement doesn't actually join the parent
products. I tried defining the reverse association in the products_controller
like this:
config.columns[:images].association.reverse = :products
.. That didn't help. I also tried adding an :order parameter to my
add_scoped_link but it was ignored (this parameter is not documented, I was
just taking a shot in the dark)
Here's the basics of the classes involved. Any ideas what I've missed?
class Product < ActiveRecord::Base
has_many :images, :as => :viewable, :dependent => :destroy
end
class Image < Asset
...
end
class Asset < ActiveRecord::Base
belongs_to :viewable, :polymorphic => true
acts_as_list :scope => :viewable
end
class Admin::ProductsController < Admin::ResourceController
layout "admin_active_scaffold"
include Admin::ProductsHelper
active_scaffold :product do |config|
config.actions = [:list, :search, :update, :delete, :create, :nested]
config.columns = [:name, :taxons, :product_properties, :description,
:permalink, :available_on, :available_publicly_on, :tax_category,
:shipping_category, :inventory_status, :count_on_hand, :images]
config.columns[:images].association.reverse = :products
config.nested.add_scoped_link(:images, :label => "Images", :page => false)
end
end
>
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en.