DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Auditing Tools for Kubernetes
  • Redefining DevOps: The Transformative Power of Containerization
  • Insider Threats and Software Development: What You Should Know
  • Real-Time Made Easy: An Introduction to SignalR
  1. DZone
  2. Data Engineering
  3. Databases
  4. Arel & ActiveRecord: The Definitive Guide to Ruby's SQL Manager

Arel & ActiveRecord: The Definitive Guide to Ruby's SQL Manager

Alec Noller user avatar by
Alec Noller
·
Jul. 15, 14 · Interview
Like (0)
Save
Tweet
Share
3.84K Views

Join the DZone community and get the full member experience.

Join For Free

If you're a Ruby developer working with SQL, you might want to check out Jiří Pospíšil's definitive guide to Arel, the SQL manager for Ruby. It's one of those libraries that you use constantly and rely on heavily, even though you might not know much about how it works, or even that it exists.  Pospíšil describes Arel as follows:

It’s all about providing frameworks with a way of building and representing SQL queries. It’s not the kind of library you would typically want to use directly (although you could as shown in a minute). Arel is meant to be the basic building block upon which frameworks build their own APIs that are more suitable for the end user.

One such framework, as most Ruby devs are certainly aware, is ActiveRecord, Rails' default ORM. Pospíšil uses ActiveRecord for most of his examples, and goes into great detail explaining the inner workings of Arel and, more importantly, Arel's relationship with ActiveRecord:

The interesting thing is the collaboration between Arel and ActiveRecord. Arel is technically independent from ActiveRecord but it needs to get the database details from somewhere and currently it uses ActiveRecord. More specifically, Arel requires ActiveRecord’s APIs. There’s even a fake ActiveRecord implementation, FakeRecord, that is used to run the Arel’s tests.

Pospíšil explores basic SELECT statements, various JOINs, the limitations of the technology, and more, pointing out the interactions between Arel and ActiveRecord for each. He evens walks you through working directly with the underlying Arel objects, even though that sort of cleverness isn't currently supported.

If you're interested in getting to know your Ruby in a bit more of an under-the-hood fashion, Pospíšil's guide to Arel is a great place to start.

sql

Opinions expressed by DZone contributors are their own.

Trending

  • Auditing Tools for Kubernetes
  • Redefining DevOps: The Transformative Power of Containerization
  • Insider Threats and Software Development: What You Should Know
  • Real-Time Made Easy: An Introduction to SignalR

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: