#22 new
Priit Tamboom

let's use 'couchrest_type'

Reported by Priit Tamboom | November 18th, 2008 @ 09:45 AM

Hi!

Thanks for couchrest!

I know it might sound horrobly idea to change type at the moment, but why not to use 'couchrest_type' instead of 'couchrest-type'. Why? Because then I can make custom map functions much nicer:

istead: if(doc['couchrest-type'] == 'MyModelName' I can write: if(doc.couchrest_type == 'MyModelName')

At the moment, all my other types are correct except couchrest-type!

What do you think about to change it?

I can make push with fixed test if it's ok.

Cheers, Priit

Comments and changes to this ticket

  • Priit Tamboom

    Priit Tamboom November 18th, 2008 @ 10:13 AM

    • Assigned user set to “J. Chris A.”

    I made patch againtst to design-doc branch.

  • hkstar

    hkstar November 19th, 2008 @ 07:16 PM

    If we're messing with things, I would actually prefer to see the field name changed to something more generic like "document_class" or "object_type" or "instance_of" or something. The label couchrest_type seems to imply that the document itself is related to CouchRest.

    Agree on losing the hyphen, though, that's just a good habit in general and makes the JS side look that much nicer.

  • Priit Tamboom

    Priit Tamboom November 20th, 2008 @ 05:33 AM

    I agree, however I don't mind using 'couchrest_type' by the way, at least I'm sure it does not clash with anything in the future. I have playied with other ruby interfaces using: ruby_class, class etc. First I was scared to use 'class' or something very general, but more I play with couchdb more I think it might be ok with very general key as well.

  • hkstar

    hkstar November 23rd, 2008 @ 05:45 PM

    Priit: I don't think it will be a problem using generic-sounding names, as long as you stay away from conflicting ruby keywords like class, type, object_id, etc. Maybe instance_of was a bad suggestion!

    Unless the developer rules differently, I think I'm going to go with record_class or document_class or something. I don't really want to rely on the built-in system anyway since I will be calling from inside multiple modules, so the couchrest-type gets written as BaseModule::SubModule::Class or similar. This might cause problems if I decide to move a class to another module so I want to specify my own names anyway.

    Maybe a way to specify the couchrest-type used would be handy to avoid the type of situation I'm talking about. Perhaps use_class_name to go under use_database?

  • James R. Bracy

    James R. Bracy December 28th, 2008 @ 09:51 PM

    Attached is a patch that makes the field is customizable, but it will default to couchrest_type. For example:

    
    class Example < CouchRest:Model
      set_inheritance_field "type"
    end
    

    Alternately you could set the field across all models by doing CouchRest::Model.inheritance_field = 'my_custom_field' or CouchRest::Model.set_inheritance_field = 'my_custom_field'`

    Hope this helps. I created 2 specs for it as well.

  • Max Aller

    Max Aller December 29th, 2008 @ 07:35 PM

    +1 James' patch with the suggestion that there be only one method for assigning a new default custom field, to reduce clutter in the code. My vote is for the "set_" variant.

  • CodeMonkeyKevin

    CodeMonkeyKevin August 13th, 2010 @ 07:52 PM

    • Milestone order changed from “0” to “0”

    +1 for James patch as couchrest_type is so odd when in multi-lang env. If not at lease _doc_type will do fine.

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

Attachments

Pages