From: Rodrigo Rosenfeld Rosas <rr.ro...@gmail.com>
Date: Tue, 17 Apr 2012 13:12:04 -0300
Local: Tues, Apr 17 2012 12:12 pm
Subject: Request for adding an "alias"/"as" to ActiveRecord
I often find myself in situations where I'm fighting against
ActiveRecord because there is no easy way to alias some tables. For example, I'm converting a legacy application. So, there is a class Field Okay, first set up is awesome! Now the issue: I'm implementing the tree view in a lazy way using AJAX, so I only need The easy way is to iterate over the fields like this: render json: fields.map {|field| } But this means fields.count "select 1 where exists(...)" queries. This works fine, but I'd prefer to have something like this: field_ids_with_children = Field.find_by_sql(['select id from And then have something like "has_children: But if you're taking enough attention, you'll see that there is a bug in This would be the correct query (simplified, not my actual case), since select id from condition_type f1 where id in (?) and exists(select 1 So, I'd like to propose adding an "alias" or "as" method to field_ids_with_children = Field.as(:f1).select(:id).where(id: Currently I couldn't find any solution to work around this issue. For field_ids_with_children = This would still raise an error since the default scope will use For this particular case, using Field.unescoped.from... would do it, but Thank you for your patience on reading all of this. Cheers, You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||