On Wednesday, September 4, 2013 3:00:43 PM UTC-7, Joshua Hansen wrote: > Here's an example: > > Let's say I have a user model (class: User) with a unique email field. > > Multiple datasets are capable of pulling the same model instances. User[1] > and User[email: '[email protected] <javascript:>'] can return the same > instance but use two different datasets. So what I'd want to be able to > determine on a model instance is, what was the specific dataset that > created it. It might even be a collection, like User.all (which, if I'm not > mistaken, is the dataset returned by User.dataset) or even something > nonspecific like User.first. user_instance.this is most likely equal to the > dataset User[<pk>] uses to get the instance. > > I did end up coding this because I couldn't find anything that seemed to > fit the bill, but like I said, me missing something isn't exactly uncommon. > Haha. >
The tactical_eager_loading plugin does something like that, but you have to call Dataset#all. In general, the dataset that retrieves the rows is decoupled from the model instance that is created. What happens is the dataset gets the rows as hashes (Dataset#fetch_rows), and then for model datasets, just calls the dataset's row_proc with that hash (inside Dataset#each). One way to handle this to override the dataset's row_proc and Dataset#each so that Dataset#each passes both the values hash and self to the row_proc, and the row_proc can then assign the dataset to an instance variable of the created model instance (or store it some other way). I'm curious as to why you'd want to use the dataset later. What's the end goal? 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/groups/opt_out.
