- Model Inheritance

Hi, I’m new to this list and to rails, so I’m sorry if this subject is
repetead or too obvious.

I have two models: Topic and University, both in production. I want to
make
University to inherit from Topic, but when I do this:

  University < Topic

My universities data just disapear (and reapears if the changes are
undone).

I’m using mongomapper and mongodb. The code is pretty big sp I’ll post
then
only if necessarily. I think this must be easy to solve.

ps: I’ve tried the deprecated _type but didn’t work.

Thanks !

On Jan 21, 10:03pm, Pedro B. [email protected] wrote:

Hi, I’m new to this list and to rails, so I’m sorry if this subject is
repetead or too obvious.

I have two models: Topic and University, both in production. I want to make
University to inherit from Topic, but when I do this:

University < Topic

My universities data just disapear (and reapears if the changes are undone).

Are you trying to setup a single table inheritance type thing? When
you say that your universities data disappears, do you mean that
University.all no longer returns any data?
Switching from your previous setup to a single table inheritance
situation means that mongomapper will be looking in the topics
collection when you do University.all, so I’m not surprised that your
university data would appear to vanish, if you haven’t done anything
to move it from its previous collection.

Fred

This is exactly it, I’m trying to add the topics behavior to the default
behavior of universities and University.all just returns []

How do I change the University? I was unable to find references to it.

2011/1/21 Frederick C. [email protected]

On Jan 22, 3:39am, Pedro B. [email protected] wrote:

This is exactly it, I’m trying to add the topics behavior to the default
behavior of universities and University.all just returns []

How do I change the University? I was unable to find references to it.

I’ve only dabbled with mongomapper, but my understanding is that if
you move from two separate collections to a single collection
inheritance setup, you’re going to need to move all the data from the
old universities collection to the topics collection

Fred

but how would I do that since all the data is missing?

well, thanks for the help! I’ll keep trying.

2011/1/22 Frederick C. [email protected]

Yeah!

It is solved, I just needed to resave all University data as Topics,
with
custom fields, and with the _type attribute.

Thanks for the answers!

2011/1/22 Frederick C. [email protected]

On Jan 22, 12:39pm, Pedro B. [email protected] wrote:

but how would I do that since all the data is missing?

Can you see it using the mongo console? I reckon the data isn’t
missing, mongomapper is just looking for it in the wrong collection.

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs