1

I'm using Mongoid 4.0.0 with Rails 4. My models map tables in another application, and I have no control over the field names.

One of the models has a field named id, which is getting coerced into Mongo's _id field. For example, when I insert a document with an id value of "something" I get

{_id:"something", id:null}

instead of

{_id:ObjectId("<hexstring>"),id:"something"}

Is there any way to avoid this coercion, make Mongoid not conflate the two fields, and leave my id field alone?

As I said, renaming the id field is not an option.

Thanks!

[edited] This is definitely not a MongoDB issue. It must be in Moped or (my guess) Mongoid.

I've tried changing the params key from :id to :_rid but this is still happening. I'm going to check out aliases, but from my first pass I don't think they're going to help -- they appear to go the wrong way.

RoUS
  • 1,888
  • 2
  • 14
  • 29

1 Answers1

0

This appears to be hardcoded into Moingoid and a pervasive assumption throughout. It's annoying enough, though, that I might come up with a patch to allow users to override the key field on a per-model basis.

Oh well.

RoUS
  • 1,888
  • 2
  • 14
  • 29