#17 ✓invalid
hkstar

Instatiating Couchrest::Model with nil vars half-succeeds

Reported by hkstar | October 29th, 2008 @ 09:54 PM

If you have a Couchrest::Model class Myclass, having set accessors up and everything, if you instantiate it while sending in undeclared variables:

Myclass.new(:name => @var.id)

This will succeed no matter if @var is nil or not:

m = Myclass.new(:name => @var.id) (irb):25: warning: Object#id will be deprecated; use Object#object_id => {"name"=>4, "couchrest-type"=>"Myclass"}

I believe it should fail noisily in this situation. It is pretty hard to think of a case where the id of nil is something you want to save.

Thoughts?

Comments and changes to this ticket

  • J. Chris A.

    J. Chris A. October 29th, 2008 @ 10:05 PM

    • State changed from “new” to “invalid”

    hmm,

    try @var && @var.id

    in this instance, all CouchRest knows is that you passed :name => 4 into it.

    checking for values of 4 is not gonna work.

    --

    however: I do have some code around that strips keys out of hashes, when their values are nil... can make for a leaner save...

  • J. Chris A.

    J. Chris A. October 29th, 2008 @ 10:06 PM

    but thanks for the ticket! keep em coming.

  • hkstar

    hkstar October 29th, 2008 @ 10:18 PM

    Oops. Momentarily confused there due to tiredness. Face, palm, etc.

    Sorry for the noise! Will keep 'em coming.

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 ยป

"CouchDB, close to the metal." <a href="http://github.com/jchris/couchrest/tree/master">CouchRest</a> is a RESTful layer for accessing CouchDB, based off CouchDB's included Javascript reference client. CouchRest also includes helpers for running large queries etc. There is also a base class for ActiveRecord / Datamapper style ORM, called CouchRest::Model.

People watching this ticket

Pages