20081128 Bp Study#15 Active Record

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    20081128 Bp Study#15 Active Record - Presentation Transcript

    1. BP Study #15 ORマッパー対決〜2008 Active Recordとか
    2. 自己紹介 • 尾崎 智仁 • ID:yuroyoro • フリーエンジニア • Java、最近はScala
    3. Blog
    4. ORマッパー 対決 ってことで
    5. Active Record
    6. ActiveRecordって? •RailsでのO/R Mapper •Railsなくてもつかえるけど •ActiveRecordパターン •Mapping定義が簡単 •class Member < ActiveRecord::Base
    7. ActiveRecordって? •DDL関係はMigrationで •Act_as_*で振る舞いを拡張可能 •動的ファインダ •Lazy Loading •Named Scope ->イカス
    8. やってみよう!
    9. ActiveRecordを使う準備 •MySqlをインストールしておく •MySqlにDatabaseを作っておく •Railsアプリを生成する •Migration書く
    10. ActiveRecordを使う - 1 Railアプリを生成 $ rails ARTest create create app/controllers create app/helpers create app/models create app/views/layouts create config/environments create config/initializers create db create doc
    11. ActiveRecordを使う - 2 Modelを生成する $ ./script/generate model member username:string password:string ¥ sex:decimal birthday:datetime last_login_time:timestamp :0:Warning: Gem::SourceIndex#search support for Regexp patterns is deprecated exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/member.rb create test/unit/member_test.rb create test/fixtures/members.yml create db/migrate create db/migrate/20081127123415_create_members.rb
    12. ActiveRecordを使う - 3 Migrateする $ rake db:migrate (in /Users/ozaki/dev/Project/sandbox/work/ARTest) == 20081127123415 CreateMembers: migrating ==================================== -- create_table(:members) -> 0.0049s == 20081127123415 CreateMembers: migrated (0.0054s) ===========================
    13. ActiveRecordを使う - 4 Consoleで確認 $ script/console Loading development environment (Rails 2.1.0) >> member=Member.find(:all) => [] >> Member.create #<Member id: 1, username: nil, password: nil, first_name: nil, last_name: nil, sex: nil, birthday: nil, last_login_time: nil, created_at: \"2008-11-27 13:16:47\", updated_at: \"2008-11-27 13:16:47\"> >> Member.find(1) => #<Member id: 1, username: nil, password: nil, first_name: nil, last_name: nil, sex: nil, birthday: nil, last_login_time: nil, created_at: \"2008-11-27 13:16:47\", updated_at: \"2008-11-27 13:16:47”>
    14. ActiveRecordを使う - 5 動的な属性ベースのファインダ >> Member.find_by_username('Test2') => #<Member id: 2, username: \"Test2\", password: nil, first_name: nil, last_name: nil, sex: nil, birthday: nil, last_login_time: nil, created_at: \"2008-11-27 13:17:04\", updated_at: \"2008-11- 27 13:21:14\">
    15. ActiveRecordを使う - 6 関連の設定 class Employee< ActiveRecord::Base belongs_to :department has_many :roles ,:through => :belongs End class Department< ActiveRecord::Base has_many :employees acts_as_tree :order => \"id\" end
    16. ActiveRecordを使う - 7 Named_scope class Member < ActiveRecord::Base named_scope :male, :conditions=>[\"sex = ?\",1] named_scope :recent, lambda {|*args| {:conditions => [\"updated_at > ?\", args.first || 1.day.ago]} } end
    17. ActiveRecord まとめ よかったさがし •Mapping定義は楽 •Pluginいっぱい •Lazy Loading •Irb上で簡単確認
    18. ActiveRecord まとめ Disってみる Disってみる •リファクタリング大変 •Migrationは計画的に •IDEの補完が… •Joinとかにがて
    19. おまけ Active Objects
    20. ActiveObjectsって? •ARパターンのJava実装 •Interfaceにgetter/setterで •manager.migrate(Person.class); •EntityManager •アノテーション •http://d.hatena.ne.jp/nattou_cur ry_2/
    21. ご清聴 ありがとう ございました

    + yuroyoroyuroyoro, 2 years ago

    custom

    819 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 819
      • 819 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 3
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories