每当我尝试调用它时:
@ships = Ship.find(:all,
:conditions => {:sold => params[:sold]},
:order => "ship.id desc")
从这个模型:
class Ship < ActiveRecord::Base
self.table_name = 'ship'
self.inheritance_column = :ruby_type
belongs_to :brand, :class_name => 'Brand', :foreign_key => :brand
belongs_to :fuel, :class_name => 'Fuel', :foreign_key => :fuel
has_many :ship_pictures, :class_name => 'ShipPicture'
has_many :reservations, :class_name => 'Reservation'
end
我最终得到了这些查询:
Ship Load (0.0ms) SELECT "ship".* FROM "ship" WHERE "ship"."sold" = 'false' ORDER BY ship.id desc
Brand Load (0.0ms) SELECT "brand".* FROM "brand" WHERE "brand"."name" = 'Percedes' LIMIT 1
Fuel Load (0.0ms) SELECT "fuel".* FROM "fuel" WHERE "fuel"."name" = 'Air' LIMIT 1
ShipPicture Load (0.0ms) SELECT "ship_picture".* FROM "ship_picture" WHERE "ship_picture"."ship_id" = 2
Brand Load (1.0ms) SELECT "brand".* FROM "brand" WHERE "brand"."name" = 'Volksship' LIMIT 1
Fuel Load (1.0ms) SELECT "fuel".* FROM "fuel" WHERE "fuel"."name" = 'Nuclear Reactor' LIMIT 1
ShipPicture Load (0.0ms) SELECT "ship_picture".* FROM "ship_picture" WHERE "ship_picture"."ship_id" = 1
为什么会这样?我没有打电话 :include 或类似的东西?我想加入 ship_pictures 并且只获得该加入的第一个结果。
第二件事:什么被认为更好:象征方式还是方法方式?