Comments on: Rails: ‘Has_many through’ Association Across Databases https://www.setfiremedia.com/blog/rails-has-many-through-association-across-databases Hot ideas for the web. Thu, 17 Dec 2020 06:45:43 +0000 hourly 1 https://wordpress.org/?v=5.5.6 By: Moschops https://www.setfiremedia.com/blog/rails-has-many-through-association-across-databases/comment-page-1#comment-1067 Thu, 09 Jul 2009 22:52:56 +0000 http://www.setfiremedia.com/blog/?p=102#comment-1067 This works until you update… I think you need

def users
@users ||= order_users.collect(&:user)
end

]]>
By: Leon https://www.setfiremedia.com/blog/rails-has-many-through-association-across-databases/comment-page-1#comment-909 Wed, 29 Oct 2008 10:09:32 +0000 http://www.setfiremedia.com/blog/?p=102#comment-909 i’m using
establish_connection(ActiveRecord::Base.configurations[“legacy_#{RAILS_ENV}”])
inside my legacy models so you can use a development and production legacy database
just my 2c

]]>
By: Leandro Gualter https://www.setfiremedia.com/blog/rails-has-many-through-association-across-databases/comment-page-1#comment-735 Fri, 17 Oct 2008 03:19:41 +0000 http://www.setfiremedia.com/blog/?p=102#comment-735 I think that the code

def orders
order = []
order_users.each do |ou|
order << ou.user
end
order
end

should be

def orders
order = []
order_users.each do |ou|
order << ou.order
end
order
end

]]>
By: Onno https://www.setfiremedia.com/blog/rails-has-many-through-association-across-databases/comment-page-1#comment-708 Wed, 15 Oct 2008 12:34:15 +0000 http://www.setfiremedia.com/blog/?p=102#comment-708 I second the “embrace collect” advise. To make this advise somewhat clearer to mere mortals, here’s a rewrite:

def users
users ||= order_users.collect {|ou| ou.user}
end

For clarification of the ampersand (&) notation, please see here.

]]>
By: aa https://www.setfiremedia.com/blog/rails-has-many-through-association-across-databases/comment-page-1#comment-699 Tue, 14 Oct 2008 19:35:13 +0000 http://www.setfiremedia.com/blog/?p=102#comment-699 embrace .collect:

def users
users ||= order_users.collect(&:user)
end

def orders
orders ||= order_users.collect(&:user)
end

]]>