rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 程序开发 » ActiveRecord

why we use abstract_class in active_record ?

  in the sample below: class BookLib < ActiveRecord::Base   self.abstract_class = true end  since abstract_class is set to true, this model class shifts to be a fade one(no table will be create for it), why we need a fade model in our project? y... « 阅读全文

发布于: 2011-09-26 10:21:06

ActiveRecord handling of obj.dup vs obj.clone

  AR seems to be handling model object dup and cloning differently fromRuby documented behavior. I've checked out both ways (as an AR modeland not) and the behavior is different. I don't see anything in theRAILS documentation about this. Am I missi... « 阅读全文

发布于: 2011-09-25 10:59:10

动态生成ActiveRecord::Base的子类

  由于需要动态生成许多表,为了在console下测试更加方便,动态生成AR::Base的子类require 'rubygems'require 'active_record'class GenerateClassattr_accessor :generate_classattr_accessor :envdef initialize(env)@env = env@generate_class = []end# 生成ActiveRecord::Base的子类... « 阅读全文

发布于: 2011-09-19 09:34:07

新的rails中activerecord拥有了检查record object是否有改变的能力

  摘要  新的rails中activerecord拥有了检查recordobject是否有改变的能力,即dirtyobject.你可以直接查询对象所有改变了的属性,如果你要使用attr=以外的方法改变对象属性的时候,可以使用attr_name_will_change!来告诉对象注意属性的变化新的rai... « 阅读全文

发布于: 2011-09-18 15:42:36

如何处置增强ActiveRecord::Base的rb文件

  现在做一个全文检索的功能,需要在model加上这么一段代码:def self.full_text_search(q, options = {}) return nil if q.nil? or q=="" default_options = {:limit => 10, :page => 1} options = default_options.merge options # get the offset based on what page we're... « 阅读全文

发布于: 2011-09-07 09:44:06

ROR-Active Record Query Interface-Title_list

  1 Retrieving Objects from the Database#检索对象1.1 Retrieving a Single Object1.1.1 Using a Primary Keyclient = Client.find(10)1.1.2 first1.1.3 last1.2 Retrieving Multiple Objects#检索多个对象1.2.1 Using Multiple Primary Keysclient = Client.find(1, 10)... « 阅读全文

发布于: 2011-08-22 13:16:20

ORM层――ActiveRecord

  ActiveRecord是Rails的ORM层。配置简单,使用方便。一个类只需要继承自ActiveRecord::Base那Rails就会自动就会认为这个类和数据库有映射关系。配置:按照使用数据库的情况来修改database.yml文件。设置关联表名:Rails默认表名是模型名的复数。如果你不想这样... « 阅读全文

发布于: 2011-08-03 13:00:36

ActiveRecord笔记

  1:类名应该是单数形式;表名应该是复数形式。如果想改变这个规则:class Sheep<ActiveRecore ::Base    set_table_name:"sheep"#或者self.table_name="sheep"end2:ruby script/consoleOrder.column_names 输入表的结构Order.columns_hash[”pay_type“] 查看pay_type字段的详细信息3: _before_type_cast 输出一个属性... « 阅读全文

发布于: 2011-07-08 18:22:36

分析ActiveRecord使用method_missing和respond_to?实现动态方法

  method_missing经常用来写Ruby的元编程。例如,如果你的UserModel有个email的属性,你就可以通过User.find_by_email('joe@example.com')来查找,这是如果User并没有定义这个方法,那么ActiveRecord::Base就会处理这样的请求。... « 阅读全文

发布于: 2011-07-08 13:19:40

ActiveRecord的概念

  ActiveRecord是什么:1.每一个数据库表对应创建一个类。类的每一个对象实例对应于数据库中表的一行记录;通常表的每个字段在类中都有相应的Field;2.ActiveRecord同时负责把自己持久化.在ActiveRecord中封装了对数据库的访问,即CRUD;3.ActiveRecord是一... « 阅读全文

发布于: 2011-07-05 16:51:59