On Tuesday, September 16, 2014 12:12:48 AM UTC-7, Куракин Александр wrote: > > Good day! > > I have some queries in my code, i.e. > *Comment.dataset.group_and_count(:creator_id).all* or some *join*s. These > queries return *Comment* but nor dataset nor hash. > > But I don't want to initialize a model at all. Because of hooks, plugins, > etc. start to work. So, I do *DB[query_above.sql].all* and it returns a > dataset. > > So I have two questions: > > 1) Is there some standard method to avoid initializing a model during > query? >
Use Dataset#naked: Comment.dataset.group_and_count(:creator_id).naked.all > > 2) Is this behavior correct? Well for *join* it is correct because of SQL > query has *SELECT `comments`.**, but for *group_and_count*? > What's the logic (to understand)? *Comment*'s methods always return > *Comment*? > All datasets have an optional row_proc, which if present is called with each underlying hash before it is yielded to the user. For model datasets, the row_proc is the model (Model.call taking a hash and returning a new Model instance). So by default on a model dataset, retrieving rows using the dataset is going to return model instances. Dataset#naked just removes the current row_proc. I suppose if backwards compatibility were not an issue, group_and_count could be changed to call naked internally, but since it is an issue, I don't think we can do that. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
