サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
パリ五輪
blog.hasmanythrough.com
Here's a gotcha: has_many :through associations do not support polymorphic access to the associated object. In this article I'll show the reasons for this limitation, and also provide an approach that lets you work with polymorphic associations without too much trouble. Let's start with some example code so I have something concrete to talk about. Here's some models for representing that an author
Happy Friday! It's Rails 3.2 day! The official release announcement mentions a few of the big changes, but I'd like to take a moment to highlight a relatively small change I was responsible for, one that I hope may make your life a little easier. From the ActiveRecord CHANGELOG: Generated association methods are created within a separate module to allow overriding and composition using `super`. Fo
This is not the post I wanted to write. The post that I wanted to write, that I in fact have mostly written and would have posted days ago if not for this distraction, was about what a great success Golden Gate Ruby Conference was and how proud we are of putting on a top-notch conference that raised the bar in many ways. But I'm the person who is responsible for the technical program at the confer
I've been using git for source code management for over a year now and I'm totally hooked. I won't rave about all the usual reasons WhyGitIsBetterThanX since it's been done already. Instead, I'm going to share how I use git for easy agile development. The basic idea is to never do anything in the master branch except use it to move changes between the remote repo and local branches. Keeping master
ActiveRecord does a great job of insulating you from a lot of the hard stuff about using SQL, and it packs the results of queries up nicely as model objects. What could be better than that? Well, sometimes you don't want all that. Sometimes you just want what you want. Let's pretend you're building a blog and want to show a little calendar in the sidebar that shows all the days on which a post was
In Ruby, #length and #size are synonyms and both do the same thing: they tell you how many elements are in an array or hash. Technically #length is the method and #size is an alias to it. In ActiveRecord, there are several ways to find out how many records are in an association, and there are some subtle differences in how they work. post.comments.count - Determine the number of elements with an S
Update: This article is now superceded by a new version that is updated for Rails 2.0 changes. Here we go. Rick Olson helped me figure out how to do bi-directional, self-referential associations using has_many :through. It's not obvious (until you know the trick), so here's how it's done. This example is for modeling digraphs. create_table "nodes" do |t| t.column "name", :string t.column "capacity
This article updates a previous version for the Rails 2.0 way of things. Since there's not much difference, I decided to fix up the example code to be more understandable. After all, not everyone is a discrete math geek. This example updates the one from the previous article. The only significant difference is that you don't need to specify the :foreign_key when using the :class_name option in a b
I've been wanting to start doing some book reviews for a while, so here goes. The folks at Apress have been kind enough to send me review copies of a couple books, so I'm going to start with one of them. First up, Pro Active Record. Title: Pro Active Record: Databases with Ruby and Rails Authors: Kevin Marshall, Chad Pytel, Jon Yurek Publisher: Apress My first thought at seeing this book was, "Hey
Way back when, I wrote about how to do Dirt Simple RCSS in Rails. Now that Rails 2.0 is upon us, it's time to get even simpler. With all the restful magic in Rails 2.0, you can get even simpler than dirt. Let's assume you have a restful User resource. You've got your "map.resources" in routes.rb, a typical User model, and a Users controller with standard views like index and show. Now you want to
Ever since I started using Rails I've been wanting a way to enforce referential integrity in the database. The Rails philosophy is to keep business logic out of the database and do it in Ruby. All those nifty validation methods are meant to take care of that. That means no foreign key constraints in the database - just use the rails validations. But which validations to use? The thing that's alway
Here's a change that has been a long time coming. (Really. The first time I heard DHH mention he wanted to do this was in March of 2006.) I liked it so much that I've been playing shepherd for it to make sure it happens. So if you're on edge, now is the time. In 1.2.x and previous, the name of the foreign key of a belongs_to association is inferred to be the name of the association's class plus "_
This is my take on the current shift to rich, in-browser JavaScript apps. Looking back over a few decades, this is the progression of how applications have been built: mainframes and dumb terminals minicomputers and smart terminals networked workstations workstations and shared code/data repositories web apps and static HTML web services and rich browser apps Translation: The main body of the appl
このページを最初にブックマークしてみませんか?
『has_many :through』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く