Em 27-04-2012 13:55, Jeremy Evans escreveu:
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 <http://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
    <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
    <http://sequel.rubyforge.org/rdoc/classes/Sequel/SQL/AliasMethods.html>

    But its documentation suggests a different usage than
    Model.dataset.as <http://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.

Humm... makes sense. Smart :)

Thanks again :)

--
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.

Reply via email to