This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| config.sequel.after_connect = proc do | |
| Sequel::Model.db.extension :pagination | |
| Sequel::Model.db.extension :pg_hstore | |
| Sequel::Model.plugin :active_model | |
| Sequel::Model.plugin :validation_helpers | |
| Sequel::Model.plugin :dirty | |
| Sequel::Model.plugin :association_proxies | |
| Sequel::Model.plugin :timestamps, update_on_create: true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Artist.eager_graph(:albums).all | |
| Artist.eager(:albums).all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # verbose, flexible version (specify which columns to join on) | |
| Album.left_join(:artists, artist_id: :id) | |
| # association "automatic" version (automatically determines which column to join on based on association on the model) | |
| Album.association_left_join(:artists) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # AR and Sequel - results in single query, *not* two | |
| Artist.where(id: Album.select(:artist_id)) | |
| # SELECT artists.* FROM artits WHERE id IN (SELECT artist_id FROM albums) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| User.where { (id > 5) & (login_count < 10) } | |
| User.where { |q| (q.id > 5) & (q.login_count < 10) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # AR & Sequel | |
| User.where(name: "Tom") | |
| User.where("name = :name", name: "Tom") | |
| User.where("name = ? OR email = ?", "Tom", "[email protected]") | |
| User.where("users.name = ?", "Tom") | |
| # AR-only | |
| User.where(users: { name: "Tom" }) | |
| # Sequel-only | |
| User.where(users__name: "Tom") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| User.where("name = ?", "Tom").first | |
| User.where(name: "Tom").first |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 2.0.0p247 :005 > pid = spawn("true") | |
| => 79236 | |
| 2.0.0p247 :006 > Process.waitpid(79236) | |
| => 79236 | |
| 2.0.0p247 :007 > Process.waitpid(79236) | |
| Errno::ECHILD: No child processes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Unicorn worker 1 | Unicorn worker 2 | |
| CREATE comment | | |
| post = Post.find(X) | DELETE post X | |
| any code | Post.find(X).destroy | |
| post.comments.create | | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| has_one :display_gallery_item, as: :imageable, class_name: "GalleryItem" | |
| class ServiceCenterPreloader | |
| class GalleryItemPreloader < ActiveRecord::Associations::Preloader::HasOne | |
| def initialize(owners, reflection) | |
| super(GalleryItem, owners, reflection, ActiveRecord::Relation.new(nil, nil)) | |
| end | |
| private | |
| def build_scope |