SlideShare a Scribd company logo
80


60


40


20


 0
  2007   2008   2009
Po w ere d by   vs
class Employee < ActiveRecord::Base
  validates_presence_of :name


CREATE TABLE employees (
  name VARCHAR(40) NOT NULL,
class Employee < ActiveRecord::Base
  validates_length_of :login,
                      :minimum => 5


CREATE TABLE employees (
  login VARCHAR(10)
    check(length(login) > 4),
begin
  emp = Employee.new(:login => '')
  emp.save_with_validation(false)
  fail
rescue ActveRecord::StatementInvalid
end
Departments   Employees
class Employee < ActiveRecord::Base
  belongs_to :department
  validates_presence_of :department


CREATE TABLE employees (
  department_id INTEGER NOT NULL
    REFERENCES departments(id),
Companies   Departments   Employees
has_many :though

company.employees.size


SELECT count(*) AS count_all
FROM employees
INNER JOIN departments
   ON employees.department_id =
      departments.id
WHERE departments.company_id = 1
SELECT count(*) AS count_all
FROM employees
WHERE company_id = 1



Companies


                ?
               Departments     Employees
company_id    department_id




Companies         Departments     Employees
id                id              id
                  company_id      company_id
                                  department_id
Companies   Departments     Employees
id          company_id      id
            department_id   company_id
                            department_id
departments

CREATE TABLE departments(
  company_id INTEGER NOT NULL
    REFERENCES companies(id),
  department_id SERIAL NOT NULL,

 PRIMARY KEY (company_id,
              department_id)
employees

CREATE TABLE employees(
  company_id INTEGER NOT NULL
     REFERENCES companies(id),
  department_id INTEGER NOT NULL,
  FOREIGN KEY
    (company_id, department_id)
    REFERENCES department
      (company_id, department_id)
departments                       company_id
 department_id                   employees


 Companies       Departments       Employees
 id              company_id        id
                 department_id     company_id
                                   department_id
# gem install composite_primary_keys
Department

class Department < ActiveRecord::Base
  set_primary_keys :company_id,
                   :department_id

 has_many :employees,
          :foreign_keys =>
            [:company_id,
             :department_id]
Company

class Company < ActiveRecord::Base
  def employees_size
    Employee.count(
      :conditions =>
        ['company_id = ?', id])
  end
CREATE VIEW big_campanies AS
SELECT * FROM companies WHERE id IN
  (SELECT company_id FROM
    (SELECT compay_id, count(id) AS c
            FROM employees
            GROUP BY company_id) AS t
    WEHRE c > 1000)
BigCampany




class BigCampany < ActiveRecord::Base
  has_many :department
end
SELECT * FROM (SELCT * FROM ...)
『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ
『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ

More Related Content

Similar to 『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ

Les20
Les20Les20
Les04
Les04Les04
BIS05 Introduction to SQL
BIS05 Introduction to SQLBIS05 Introduction to SQL
BIS05 Introduction to SQL
Prithwis Mukerjee
 
Les04
Les04Les04
Les05
Les05Les05
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
mukesh24pandey
 
base de datos ejemplo
base de datos ejemplo base de datos ejemplo
base de datos ejemplo
Fabian Matamala
 
sql language
sql languagesql language
sql language
moman abde
 
Build .NET Applications with Reporting and Dashboard
Build .NET Applications with Reporting and DashboardBuild .NET Applications with Reporting and Dashboard
Build .NET Applications with Reporting and Dashboard
Iron Speed
 
Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03
Thuan Nguyen
 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMS
gaurav koriya
 
Constraint Optimization
Constraint OptimizationConstraint Optimization
Constraint Optimization
Oren Nakdimon
 
Les08
Les08Les08
Sql task answers
Sql task answersSql task answers
Sql task answers
Nawaz Sk
 
Reporting aggregated data using the group functions
Reporting aggregated data using the group functionsReporting aggregated data using the group functions
Reporting aggregated data using the group functions
Syed Zaid Irshad
 
Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)
Tâm
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answers
Nawaz Sk
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09
Thuan Nguyen
 
Unidad 4 actividad 1
Unidad 4 actividad 1Unidad 4 actividad 1
Unidad 4 actividad 1
KARY
 
Les18
Les18Les18

Similar to 『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ (20)

Les20
Les20Les20
Les20
 
Les04
Les04Les04
Les04
 
BIS05 Introduction to SQL
BIS05 Introduction to SQLBIS05 Introduction to SQL
BIS05 Introduction to SQL
 
Les04
Les04Les04
Les04
 
Les05
Les05Les05
Les05
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
 
base de datos ejemplo
base de datos ejemplo base de datos ejemplo
base de datos ejemplo
 
sql language
sql languagesql language
sql language
 
Build .NET Applications with Reporting and Dashboard
Build .NET Applications with Reporting and DashboardBuild .NET Applications with Reporting and Dashboard
Build .NET Applications with Reporting and Dashboard
 
Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03
 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMS
 
Constraint Optimization
Constraint OptimizationConstraint Optimization
Constraint Optimization
 
Les08
Les08Les08
Les08
 
Sql task answers
Sql task answersSql task answers
Sql task answers
 
Reporting aggregated data using the group functions
Reporting aggregated data using the group functionsReporting aggregated data using the group functions
Reporting aggregated data using the group functions
 
Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answers
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09
 
Unidad 4 actividad 1
Unidad 4 actividad 1Unidad 4 actividad 1
Unidad 4 actividad 1
 
Les18
Les18Les18
Les18
 

More from Naoto Takai

私と自分戦略
私と自分戦略私と自分戦略
私と自分戦略
Naoto Takai
 
JRubyによるエンタープライズweb開発
JRubyによるエンタープライズweb開発JRubyによるエンタープライズweb開発
JRubyによるエンタープライズweb開発
Naoto Takai
 
地域.rbのご提案
地域.rbのご提案地域.rbのご提案
地域.rbのご提案
Naoto Takai
 
JRuby最新事情@札幌
JRuby最新事情@札幌JRuby最新事情@札幌
JRuby最新事情@札幌
Naoto Takai
 
JRoRでGAE/Jの手引き
JRoRでGAE/Jの手引きJRoRでGAE/Jの手引き
JRoRでGAE/Jの手引き
Naoto Takai
 
5分でわかるJRuby最新事情
5分でわかるJRuby最新事情5分でわかるJRuby最新事情
5分でわかるJRuby最新事情
Naoto Takai
 
JRuby on Rails and Thread Safety
JRuby on Rails and Thread SafetyJRuby on Rails and Thread Safety
JRuby on Rails and Thread Safety
Naoto Takai
 

More from Naoto Takai (7)

私と自分戦略
私と自分戦略私と自分戦略
私と自分戦略
 
JRubyによるエンタープライズweb開発
JRubyによるエンタープライズweb開発JRubyによるエンタープライズweb開発
JRubyによるエンタープライズweb開発
 
地域.rbのご提案
地域.rbのご提案地域.rbのご提案
地域.rbのご提案
 
JRuby最新事情@札幌
JRuby最新事情@札幌JRuby最新事情@札幌
JRuby最新事情@札幌
 
JRoRでGAE/Jの手引き
JRoRでGAE/Jの手引きJRoRでGAE/Jの手引き
JRoRでGAE/Jの手引き
 
5分でわかるJRuby最新事情
5分でわかるJRuby最新事情5分でわかるJRuby最新事情
5分でわかるJRuby最新事情
 
JRuby on Rails and Thread Safety
JRuby on Rails and Thread SafetyJRuby on Rails and Thread Safety
JRuby on Rails and Thread Safety
 

Recently uploaded

WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 

Recently uploaded (20)

WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 

『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ

  • 1.
  • 2.
  • 3. 80 60 40 20 0 2007 2008 2009
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. Po w ere d by vs
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. class Employee < ActiveRecord::Base validates_presence_of :name CREATE TABLE employees ( name VARCHAR(40) NOT NULL,
  • 18. class Employee < ActiveRecord::Base validates_length_of :login, :minimum => 5 CREATE TABLE employees ( login VARCHAR(10) check(length(login) > 4),
  • 19. begin emp = Employee.new(:login => '') emp.save_with_validation(false) fail rescue ActveRecord::StatementInvalid end
  • 20. Departments Employees
  • 21. class Employee < ActiveRecord::Base belongs_to :department validates_presence_of :department CREATE TABLE employees ( department_id INTEGER NOT NULL REFERENCES departments(id),
  • 22.
  • 23.
  • 24. Companies Departments Employees
  • 25. has_many :though company.employees.size SELECT count(*) AS count_all FROM employees INNER JOIN departments ON employees.department_id = departments.id WHERE departments.company_id = 1
  • 26. SELECT count(*) AS count_all FROM employees WHERE company_id = 1 Companies ? Departments Employees
  • 27. company_id department_id Companies Departments Employees id id id company_id company_id department_id
  • 28. Companies Departments Employees id company_id id department_id company_id department_id
  • 29. departments CREATE TABLE departments( company_id INTEGER NOT NULL REFERENCES companies(id), department_id SERIAL NOT NULL, PRIMARY KEY (company_id, department_id)
  • 30. employees CREATE TABLE employees( company_id INTEGER NOT NULL REFERENCES companies(id), department_id INTEGER NOT NULL, FOREIGN KEY (company_id, department_id) REFERENCES department (company_id, department_id)
  • 31. departments company_id department_id employees Companies Departments Employees id company_id id department_id company_id department_id
  • 32. # gem install composite_primary_keys
  • 33. Department class Department < ActiveRecord::Base set_primary_keys :company_id, :department_id has_many :employees, :foreign_keys => [:company_id, :department_id]
  • 34. Company class Company < ActiveRecord::Base def employees_size Employee.count( :conditions => ['company_id = ?', id]) end
  • 35.
  • 36.
  • 37.
  • 38. CREATE VIEW big_campanies AS SELECT * FROM companies WHERE id IN (SELECT company_id FROM (SELECT compay_id, count(id) AS c FROM employees GROUP BY company_id) AS t WEHRE c > 1000)
  • 39. BigCampany class BigCampany < ActiveRecord::Base has_many :department end
  • 40. SELECT * FROM (SELCT * FROM ...)