2009年2月4日 星期三

Activerecord memo (1)

1. 如果table name不合 rails 的規則時, 可以自己設定
2. ActirveRecord 提供了一些跟欄位相關的method
3. 除了table column的屬性之外, model 也可以拿到其他的屬性

4. Facade column, 有些時候欄位的格式不是最好用的, 如上面的浮點數 string, 這時就可以利用read_attribute 和 write_attribute來達到

5. before_type_cast, ActiveRecord 會把 attribute reader (無論是attr_reader 或 read_attribute)讀回來的東西強制轉成Ruby type(根據database 的column type 去決定想轉成啥),
6. primary_key 也可以自己指定, 而我們仍是用 id 這樣的屬性去呼叫這個primary key

7. find object 的時候如果是直接照主鍵去找的才會丟 RecordNotFound

沒有留言: