一对多关联应该借助连接表吗

一对多关联应该借助连接表吗

从书上看到,多对多关联是借助php?name=%C1%AC%BD%D3" onclick="tagshow(event)" class="t_tag">连接表来实现的,可是我的表关系是一对多,php?name=rails" onclick="tagshow(event)" class="t_tag">rails还是建立了一张php?name=%C1%AC%BD%D3" onclick="tagshow(event)" class="t_tag">连接表,这是为什么?
例如:a has many b,b has many c,用ActiveRecord的find实现:

[Copy to clipboard] [ - ]
@abc = A.find(:all, :include => [:cs=>;:b], :limit => 2)
这一句中的:include => [:cs=>;:b], 是什么用法?还想请教
我也有三张表之间两个has_many关系,用include后rails生成的sql语句只用到两个left out join呀
我的用法是这样

[Copy to clipboard] [ - ]
:include 好象只有性能上的作用..
两表关系
 class Order < ActiveRecord::Base
  has_many :line_items
 class LineItem < ActiveRecord::Base
  belongs_to :order
进行查询
 item1=Order.find(:all,:include=>:line_items) log产生
 Order Load Including Associations (0.016000) SELECT orders.`id` AS t0_r0, orders.`name` AS t0_r1, orders.`address` AS t0_r2, orders.`email` AS t0_r3, orders.`pay_type` AS t0_r4, line_items.`id` AS t1_r0, line_items.`product_id` AS t1_r1, line_items.`order_id` AS t1_r2, line_items.`quantity` AS t1_r3, line_items.`total_price` AS t1_r4 FROM orders LEFT OUTER JOIN line_items ON line_items.order_id = orders.id 
 item1[0].line_items[0] 访问时不再查询 无log产生

 item2=Order.find(:all) log产生
 Order Load (0.000000) SELECT * FROM orders 
 item2[0].line_items[0]
 访问时再查询 log产生
 LineItem Load (0.000000) SELECT * FROM line_items WHERE (line_items.order_id = 1) [

自己学习的结果
引用:
原帖由 lgn21st 于 2007-12-20 01:18 发表
我也有三张表之间两个has_many关系,用include后rails生成的sql语句只用到两个left out join呀
我的用法是这样

A.find(:first, :include => {:bs => :cs})