On Friday, April 27, 2012 9:34:29 AM UTC-7, Rodrigo Rosenfeld Rosas wrote: > > Em 27-04-2012 13:19, Jeremy Evans escreveu: > > On Friday, April 27, 2012 5:31:16 AM UTC-7, Rodrigo Rosenfeld Rosas wrote: >> >> Em 26-04-2012 22:16, Jeremy Evans escreveu: >> >> 3) There is already a Dataset#as method that does something different, >> and many Model class methods call the dataset method of the same, so adding >> a Model.as method that returns a modified dataset would introduce an >> apparent inconsistency. >> >> >> Sorry I couldn't understand this. If you don't mind, an example might >> help here. >> > > Many model class methods just call the dataset method with the same name. > For example, you can do: > > Model.where(...) > > instead of: > > Model.dataset.where(...) > > But since Model.dataset.as already exists and operates differently than > your proposed usage (returning an Sequel::SQL::AliasedExpression), Model.as > would appear inconsistent in this regard. > > > Humm... what does it do? Believe me, I tried to look for "as" in the > Dataset documentation but couldn't find it: > > http://sequel.rubyforge.org/rdoc/classes/Sequel/Dataset.html >
> What is this useful for? > > I could only find this: > > http://sequel.rubyforge.org/rdoc/classes/Sequel/SQL/AliasMethods.html > > But its documentation suggests a different usage than Model.dataset.as(). > > AliasMethods is listed under Included Modules on the Dataset RDoc page. Among other things, it allows you do to stuff like: DB[:albums].join(DB[:artists].where(:name.like('A%')).as(:a), :id=>:artist_id) Joining to a subselect and using an alias for the join. > Well, providing an AliasedExpression to eager_graph could theoretically > be a way to implement what you want (as it is currently invalid). Looking > at the internals, it would require some refactoring, but at least it's a > possibility. > > > Well, if there isn't a less verbose alternative for those using Sequel > without the core extensions, I would be fine with it. > > Maybe I could alias Sequel in my application to S. > > So, instead of Sequel.as(:user, :u), I'd use S.as(:user, :u) and > S.~(email: nil). > > Yep, you could certainly do that to decrease the verbosity. > I'll consider a patch that has eager_graph treat AliasedExpressions as > overriding the alias base to use for the given association. > > > Great, thanks. I'll try to work on such patch as soon as I find some free > hours. > > Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/xZi98uCYWP8J. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
