Bonjour à toutes & à tous,
J'ai le souci suivant: retrouver pour un produit les catégories qui lui sont liées et qui répondent à un datatype donné, datatype défini lui-même dans une autre table...
1. TABLES
products: id + autres champs
links_category_product: category (int), product (int)
categories: id, datatype(int) + autres champs
datatypes: id, description(string)
2. CLASSES
class Datatype
has_many :categories
end
class Category
belongs_to :datatype, :class_name => "Datatype", :foreign_key => :datatype
has_many :link_category_products, :foreign_key => :category
has_many :products, :class_name => "Product", :through => :link_category_products
end
class LinkCategoryProduct
set_table_name "links_category_product"
belongs_to :category, :class_name => "Category", :foreign_key => :category
belongs_to :product, :class_name => "Product", :foreign_key => :product
end
class Product
has_many :link_category_products, :foreign_key => :product
has_many :categories, :class_name => "Category",
:through => :link_category_products do
def find_these(name)
find :all, :conditions =>[ :categories.datatype, :datatype.description == name]
end
end
end
3. CONTROLLER lists_controller.rb
class ListsController
def list_products
@items=Product.find(:all)
end
end
4. VUE list_products.html.erb
dans une table:
% @items.each do |item| %
tr - td
%=h item.categories.find_these("par_exemple") %
/td - tr
% end %
5. ERROR
undefined method `datatype' for :categories:Symbol
Ca coince dans le 'do'... de la dépendance 'categories' de la classe Product...?
Au secours, plize!
6. Merci à toutes les bonnes âmes secourables.
Nicolas
|
il y a 7 heures 42 min
il y a 10 heures 3 min
il y a 1 jour 19 heures
il y a 4 jours 1 heure
il y a 6 jours 14 heures
il y a 6 jours 15 heures
il y a 6 jours 15 heures
il y a 6 jours 19 heures
il y a 1 semaine 13 heures
il y a 1 semaine 13 heures