On Jul 7, 2:11 pm, Phrogz <[email protected]> wrote:
> Alternatively:
> * Is there an existing, better way to do this already?
Dataset#from_self, though you can't give the dataset an explicit alias
if you do that. Modifying from_self to take an options hash and
an :alias option would be my recommendation for how to handle this.
I'd gladly accept a patch that did that.
> * Would it be possible to change Dataset#as to return a Dataset while
> also allowing the result to be used where AliasedExpression is
> currently used, without adding an additional level of indirection in
> the result? (This is how I personally had hoped and expected #as to
> work.)
It might be possible, but I don't recommend that approach. The
easiest way to implement it would require adding a subclass of
SQL::AliasedExpression that acted as a proxy for the dataset, where
any method called on it would return a copy with the same alias and
the modified dataset. I'm generally against that as I find it makes
the code more difficult to understand. However, if you want to try
out that approach:
class Sequel::Dataset
def as(aliaz)
Sequel::SQL::AliasedDataset.new(self, aliaz)
end
end
class Sequel::SQL::AliasedDataset < Sequel::SQL::AliasedExpression
def method_missing(*args, &block)
ds = @expression.send(*args, &block)
ds.is_a?(Sequel::Dataset) ? Sequel::SQL::AliasedDataset.new(ds,
@aliaz) : ds
end
end
Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
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
-~----------~----~----~----~------~----~------~--~---