Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Instatiating Couchrest::Model with nil vars half-succeeds

#17

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?

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

State: invalid
Milestone: none
Assigned to: J. Chris A. J. Chris A.

Activity

  1. J. Chris A.
    J. Chris A.
    • 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...

    October 29th, 2008 @ 10:05 PM

  2. J. Chris A.
    J. Chris A.

    but thanks for the ticket! keep em coming.

    October 29th, 2008 @ 10:06 PM

  3. hkstar
    hkstar

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

    Sorry for the noise! Will keep 'em coming.

    October 29th, 2008 @ 10:18 PM

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.