On 13 July 2015 at 19:20, tamouse pontiki <
tamous...@gmail.com> wrote:
> A quick correction on Colin's suggestion:
>
> On Mon, Jul 13, 2015 at 2:44 AM, Colin Law <
cla...@gmail.com> wrote:
>>
>> On 13 July 2015 at 01:10,
j...@via.net <
j...@via.net> 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.