Rails 3 的active record和其他
发布日期:2021-09-29 20:08:49 浏览次数:5 分类:技术文章

本文共 2549 字,大约阅读时间需要 8 分钟。

今天,徘徊在几个问题之间简单流水帐,复制一下
现在的Rails版本是3.0.7
看active record呢
[url]http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html[/url]
[url]http://api.rubyonrails.org/classes/ActiveRecord/Base.html[/url]
上面的官网API看起来很不错
之前版本如下
[url]http://ar.rubyonrails.org/classes/ActiveRecord/Base.html[/url]
Company.where(   "id = :id AND name = :name AND division = :division AND created_at > :accounting_date",   { :id => 3, :name => "37signals", :division => "First", :accounting_date => '2005-01-01' } ).first Student.where(:first_name => "Harvey", :status => 1) Student.where(params[:student]) User.create([{ :first_name => 'Jamie' }, { :first_name => 'Jeremy' }]) do |u|   u.is_admin = false end Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date] > [#
"The Cheap Man Buys Twice"}>, ...]
关于relation
TreeMixin.find :all, :joins => :children # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ... TreeMixin.find :all, :joins => {:children => :parent} # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ...                             INNER JOIN parents_mixins ... TreeMixin.find :all, :joins => {:children => {:parent => :children}} # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ...                             INNER JOIN parents_mixins ...                             INNER JOIN mixins childrens_mixins_2
在rails 3下卸载active record
[quote]
The rails command that generates the application template now has an option -O, which tells it to skip ActiveRecord.
If you don't feel like rerunning rails, you should check the following in your existing app:
Check that your config/application.rb doesn't have require 'rails/all' or require "active_record/railtie". Instead, for a standard Rails setup without ActiveRecord, it should have only the following requires:
require File.expand_path('../boot', __FILE__)
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
# Auto-require default libraries and those for the current Rails environment.
Bundler.require :default, Rails.env
If, in config/application.rb, you are using the config.generators section, make sure it doesn't have the line g.orm :active_record. You can set this explicitly to nil, if you want, but this should be the default when g.orm is completely omitted.
Optional, but in your Gemfile, remove the gem line that loads the module for your database. This could be the line gem "mysql" for example.
[/quote]

转载地址:https://blog.csdn.net/horace_lee/article/details/83924442 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Rails 3 active record 根据boolean字段删除
下一篇:搜索上级dom对象并隐藏,点击隐藏父元素

发表评论

最新留言

很好
[***.229.124.182]2024年04月03日 20时39分45秒