On 13 July 2015 at 19:20, tamouse pontiki <[email protected]> wrote: > A quick correction on Colin's suggestion: > > On Mon, Jul 13, 2015 at 2:44 AM, Colin Law <[email protected]> wrote: >> >> On 13 July 2015 at 01:10, [email protected] <[email protected]> wrote: >> > class Asset < ActiveRecord::Base >> > belongs_to :site >> > >> > # class variable :name >> > >> > end >> > >> > class Site < ActiveRecord::Base >> > has_many :assets >> > >> > # class var x, y, z >> > >> > end >> > >> > Is there a dynamic finder that will traverse the inner join: >> > >> > e.g. Site.find_by_asset_name("xyzzy") >> >> Asset.where( name: 'xyzzy').site > > > Asset.find_by(name: 'xyzzy').site > > Because .where returns a collection, .find_by returns the first one found. > > Asset.where(name: 'xyzzy').first = Asset.find_by(name: 'xyzzy')
Good call, you are right. Thanks. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvLbr%2B3LfD-4dLH9tVX-oh2iA15gamg%3D43RdYiVmbHVKA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

