26 Dec '13, 4am

Rails Associations With Multiple Foreign Keys - Pivotal Labs «

Recently we had a situation where we inherited a schema and two of the models were joined using multiple foreign keys. The Rails associations API doesn’t appear to offer any good solutions to this problem. You can specify a single foreign_key and a single primary_key, but nothing really for multiple keys. One solution would be to use the Proc syntax for the :conditions option to specify the second column. has_many :others, :foreign_key => :fk_1, :primary_key => :first_primary_column, :conditions => Proc.new { {:fk_2 => other_primary_column} } Here the proc is called on our instance of the primary model, so we can just reference the other_primary_column and the value of the current instance will be used in the conditions. This will work for single models, but will not work if you are trying to eager load the association with an `includes` statement. For eager loading, what ...

Full article: http://pivotallabs.com/rails-associations-with-multiple-f...

Tweets

This echoes my feelings on Cucumber

pivotallabs.com 27 Dec '13, 12am

I had really poor experiences with Cucumber. The annoyance with Cucumber comes nearly all from a case of indirection. If d...

@lizuselton Rails tries to be really (sometimes...

api.rubyonrails.org 29 Dec '13, 5am

Creates a Cycle object whose to_s method cycles through elements of an array every time it is called. This can be used for...

@lizuselton Rails tries to be really (sometimes...

api.rubyonrails.org 29 Dec '13, 5am

The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones withou...

#Rails 4.1 beta1 now available!

rubyflow.com 25 Dec '13, 9pm

Rails 4.1 beta1 now available Posted by kalv on December 18, 2013 — 0 comments Rails 4.1 beta has been released just in ti...

@barinek just came across your app builder post...

pivotallabs.com 29 Dec '13, 6pm

Recently I’ve been working on a small spike intended to help jumpstart our Rails application development in the Pivotal La...

A single Engineer, Rails, 10 Mil pageviews/day....

railsinside.com 28 Dec '13, 1pm

is an online knitting and crochet community run by husband and wife team Casey and Jessica Forbes. A few weeks ago they di...

@sanjay can you use a has_and_belongs_to_many a...

guides.rubyonrails.org 05 Jan '14, 11pm

is a connection between two Active Record models. Associations are implemented using macro-style calls, so that you can de...

@hireDave found a better way - most of our apps...

pivotallabs.com 31 Dec '13, 4am

You might call this post Part 2 in a component based architecture series. The first post describes a solution for better o...

What every girl needs to keep her keys safe! A ...

twitter.com 26 Dec '13, 9am

To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content,...

Form-backing objects for fun and profit - Pivot...

pivotallabs.com 01 Jan '14, 4am

class Forms::Registration # ActiveModel plumbing to make `form_for` work extend ActiveModel::Naming include ActiveModel::C...