Building your app (1) <ul><li>Modeling the data </li></ul>Raymond van Dongelen | NHL |  www.webxy.nl
Datamodel <ul><li>Should prevent storing the same information twice </li></ul><ul><li>Should guard relations in the data <...
Contents <ul><li>Datamodel </li></ul><ul><li>ActiveRecord </li></ul><ul><li>Sample application </li></ul>
Ruby and data <ul><li>All database handling is done in the model </li></ul><ul><li>Powerful features to validate data, gua...
Ruby naming <ul><li>Table name plural </li></ul><ul><li>Key in a table “id” </li></ul><ul><li>Reference to another table “...
ActiveRecord(1) <ul><li>Validators: </li></ul><ul><li>validates_presence_of </li></ul><ul><li>validates_uniqueness_of </li...
ActiveRecord(2) <ul><li>Example: </li></ul><ul><li>class Agenda < ActiveRecord::Base </li></ul><ul><li>belongs_to :user </...
ActiveRecord (3) <ul><li>@agenda = Agenda.find(1) </li></ul><ul><li>puts (@agenda.user.name)  </li></ul><ul><li><== We are...
ActiveRecord (4) <ul><li>Dynamic find </li></ul><ul><li>Agenda.find_all_name (“Home”) </li></ul><ul><li>User.find_all_by_e...
ActiveRecord (5) <ul><li>Many many powerful features  </li></ul><ul><li>Read chapter 14 agile web development with Ruby on...
Sample application User Project Task Subtask User can be in many projects Project can have many users A project has many t...
Upcoming SlideShare
Loading in...5
×

Datamodel in Ruby

3,259

Published on

A short presentation followed by a demo (not included) of the capabilities of Ruby on Rails for databases.

Published in: Business, Technology
1 Comment
5 Likes
Statistics
Notes
  • Exceptional slideshow. Very clear and helpful
    Sharika
    http://winkhealth.com http://financewink.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
3,259
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
1
Likes
5
Embeds 0
No embeds

No notes for slide

Datamodel in Ruby

  1. 1. Building your app (1) <ul><li>Modeling the data </li></ul>Raymond van Dongelen | NHL | www.webxy.nl
  2. 2. Datamodel <ul><li>Should prevent storing the same information twice </li></ul><ul><li>Should guard relations in the data </li></ul><ul><li>Should be able to cope with changing data structure </li></ul>
  3. 3. Contents <ul><li>Datamodel </li></ul><ul><li>ActiveRecord </li></ul><ul><li>Sample application </li></ul>
  4. 4. Ruby and data <ul><li>All database handling is done in the model </li></ul><ul><li>Powerful features to validate data, guard relations, search data. </li></ul><ul><li>All data is wrapped in Ruby classes </li></ul><ul><li>SQL is almost never needed </li></ul>
  5. 5. Ruby naming <ul><li>Table name plural </li></ul><ul><li>Key in a table “id” </li></ul><ul><li>Reference to another table “table_id” </li></ul>
  6. 6. ActiveRecord(1) <ul><li>Validators: </li></ul><ul><li>validates_presence_of </li></ul><ul><li>validates_uniqueness_of </li></ul><ul><li>Relations: </li></ul><ul><li>belongs_to </li></ul><ul><li>has_one </li></ul><ul><li>has_and_belongs_to_many </li></ul><ul><li>has_many </li></ul>
  7. 7. ActiveRecord(2) <ul><li>Example: </li></ul><ul><li>class Agenda < ActiveRecord::Base </li></ul><ul><li>belongs_to :user </li></ul><ul><li>validates_presence_of :user, :message => &quot;cannot be empty&quot; </li></ul><ul><li>end </li></ul>
  8. 8. ActiveRecord (3) <ul><li>@agenda = Agenda.find(1) </li></ul><ul><li>puts (@agenda.user.name) </li></ul><ul><li><== We are able to display the user, it is automatically fetched </li></ul>
  9. 9. ActiveRecord (4) <ul><li>Dynamic find </li></ul><ul><li>Agenda.find_all_name (“Home”) </li></ul><ul><li>User.find_all_by_email (“ [email_address] ”) </li></ul>
  10. 10. ActiveRecord (5) <ul><li>Many many powerful features </li></ul><ul><li>Read chapter 14 agile web development with Ruby on Rails </li></ul>
  11. 11. Sample application User Project Task Subtask User can be in many projects Project can have many users A project has many tasks A task has many subtasks Sample can be found on http://www.webxy.nl/?p=63

×