- 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 !

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 &lt; 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.

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.

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

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!