2008-04-03
find_by_sql的强大,复杂查询中的不属于model的列一样可以当成model的属性用
关键字: activerecode rails
find_by_sql( ) can also be used to create model objects containing derived column data. If you use the as xxx SQL syntax to give derived columns a name in the result set, this name will be used as the name of the attribute.
items = LineItem.find_by_sql("select *, " + " quantity*unit_price as total_price, " +
" products.title as title " + " from line_items, products " +
" where line_items.product_id = products.id ")
li = items[0]
puts "#{li.title}: #{li.quantity}x#{li.unit_price} => #{li.total_price}"
发表评论
最新评论
-
经典正则表达式(希望给自 ...
很好.
-- by lirong1978sdo -
[原创]用tapestry4.0.x ...
好东西!
-- by jiangyh52 -
[原创]用tapestry4.0.x ...
呵呵,受教了。我也用Servlet做过!
-- by mercyblitz -
为什么各大银行的网上银行 ...
ray_linn 写道weiqingfei 写道ray_linn 写道gigix ...
-- by weiqingfei -
为什么各大银行的网上银行 ...
说来说去又回到开始的话题“没有绝对安全的系统”就能够推出“没必要选择比较安全的系 ...
-- by gigix







评论排行榜