In my usage I've noticed that accessors (instance.field)  work on
joins derived from model objects, but the hash access methods
(record[:field]) will also work for all fields of the result whether
from the model or the joined table. So I don't think any change would
be required to get what you are asking for.
I've been using the hash method for accessing fields where the lower
level implementation may change, e.g direct SQL is required.
Mike

On Nov 3, 8:18 am, Jeremy Evans <[email protected]> wrote:
> On Nov 2, 10:26 pm, Iain Barnett <[email protected]> wrote:
>
>
>
>
>
>
>
>
>
> > Hi,
>
> > While trying out some new associations with dataset procs, I noticed that
> > joins to a model would return a result as an instance of that model. For
> > example:
>
> >     User.join( Role )
> >     => #<Sequel::SQLite::Dataset: "SELECT * FROM `users` INNER JOIN
> > `roles`">
> >     User.join( Role ).first.class
> >     => User
>
> > I would expect a hash, as in my mind it's equivalent to
>
> >     DB[:users].join( DB[:roles] )
> >     => #<Sequel::SQLite::Dataset: "SELECT * FROM `users` INNER JOIN (SELECT
> > * FROM `roles`) AS 't1'">
> >     DB[:users].join( DB[:roles] ).first.class
> >     => Hash
>
> > Is there an option to make it return a hash? Otherwise, the extra fields
> > don't have accessors as they're not defined on the model. I could use
> > `User.join( Role ).to_hash.first` but that isn't quite the same thing, and
> > my first thought would be that it added a lot of overhead, especially to
> > large datasets (but then I was wrong about the hash too! :)
>
> Dataset#naked does what you want (removes the row_proc that turns
> hashes into model objects).  I wouldn't expect Model.join to remove
> the row_proc, I doubt most other Sequel users would expect it, and it
> would break backwards compatibility.  If you want joins to remove the
> row_proc by default, you can easily do it yourself:
>
>   Model.def_dataset_method(:join_table){|*a, &block| super(*a,
> &block).naked}
>
> 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.

Reply via email to