Your SlideShare is downloading. ×
0
Datamodel in Ruby
Datamodel in Ruby
Datamodel in Ruby
Datamodel in Ruby
Datamodel in Ruby
Datamodel in Ruby
Datamodel in Ruby
Datamodel in Ruby
Datamodel in Ruby
Datamodel in Ruby
Datamodel in Ruby
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Datamodel in Ruby

3,236

Published on

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

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,236
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
1
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Building your app (1) <ul><li>Modeling the data </li></ul>Raymond van Dongelen | NHL | www.webxy.nl
  • 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. Contents <ul><li>Datamodel </li></ul><ul><li>ActiveRecord </li></ul><ul><li>Sample application </li></ul>
  • 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. 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. 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. 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. 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. 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. 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. 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

×