On Mar 16, 1:56 am, David Lee <[email protected]> wrote: > Hey Jeremy, > > Current behavior in Sequel seems to be: > > User.first.items_dataset[2] > # => SELECT * FROM "items" WHERE ("items"."user_id" = 1) LIMIT 2 > > I think it should be: > > User.first.items_dataset[2] > # => SELECT * FROM "items" WHERE ("items"."user_id" = 1) AND > ("Items"."id" = 2) > > Is there a reason for the current behavior, or is this a bug?
In the master branch, Dataset#[] will print a deprecation message if you give it an integer, and it will raise an exception in 3.0. The reason for the current behavior is that Dataset#[] just calls Dataset#first, and User.first.items_dataset.first(2) returns the first 2 records in the dataset. You can't have the behavior you specify generally, as datasets don't know about primary keys. Model#[] can take a single value and lookup by primary key, Dataset#[] doesn't have that ability. Now, we could add it to model datasets, by checking for a non-hash value and using the model's primary key. I'd be open to adding that in 3.0. If you want to work on a patch, I'd certainly consider it. 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 -~----------~----~----~----~------~----~------~--~---
