顯示具有 db 標籤的文章。 顯示所有文章
顯示具有 db 標籤的文章。 顯示所有文章

2008年11月14日 星期五

db,connection,execute,sql

http://wiki.rubyonrails.org/rails/pages/HowtoQueryTheDatabaseDirectly
http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001794

2008年8月21日 星期四

polymphic, comment,db

use polymphic 's benefit
would not need the new table, just change the type could be used for the new model

如果model的相似度高例如 comment , 一個網站裡面很多都可以需要comment

就可以用這個


[forum model]
has_many :comments, :as => :record

[record model]
has_many :comments, :as => :record

[comment model]
belongs_to :record, :polymorphic => true

[comments table]
create_table "comments", :force => true do |t|
t.text "content"
t.integer "record_id", :limit => 11, :null => false
t.string "record_type"
end

Time db

Time#to_s(:db) ignores Time#zone -- example:

>> Time.mktime(2008, 06, 20, 0, 31, 7).to_s(:db)
=> "2008-06-20 00:31:07"
>> Time.utc(2008, 06, 20, 0, 31, 7).to_s(:db)
=> "2008-06-20 00:31:07"