#1113 suggestion

add an exists? method

Reported by BrianTheCoder | October 28th, 2009 @ 03:22 PM

basically it just does a first query and checks if there is a record that satisfies the query. My basic implementation

def exists?(query = {}); !first(query).blank? end

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 28th, 2009 @ 06:28 PM

    • State changed from “new” to “suggestion”

    Actually the plan was to optimize Collection#any? for that purpose. Currently it lazy loads the collection, but in the future what it'll do is check the loaded entries for any records, and if it doesn't find any it'll do a !first(query.merge(:fields => key)).nil? like you've done here. The { :fields => key } is just to avoid pulling a whole record back uncessarily.

    There would also be a Model#any? added as well. Here's the proposed API for DM 1.0:


  • BrianTheCoder

    BrianTheCoder October 28th, 2009 @ 11:23 PM

    Awesome. Looking forward to all of it :D

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket