Bypassing automatic STI generation

Hi,

Let’s say I have the following:

Product < AR
Memberships < Product

I know that the product with id 10 has its type column set to
“Membership”, but still I’d like to treat it as a regular product.

So if I do: Product.find(10), Rails returns a Membership object.

Is it possible to tell rails to not care about STI and to simply return
a Product object?

Regards,

On 11 March 2010 14:26, Fernando P. [email protected] wrote:

Is it possible to tell rails to not care about STI and to simply return
a Product object?

But it is a Membership object… ?:-/

But if you have to have it as a Product for some reason, you can use
the ActiveRecord::Base “becomes” method:

But it is a Membership object… ?:-/

But if you have to have it as a Product for some reason, you can use
the ActiveRecord::Base “becomes” method:
ActiveRecord::Base
It’s a Membership indeed, but in the admin section of my app, I don’t
need to recode a specific controller for memberships, they can use the
products_controller which is fine and defining :controller => “products”
won’t do the trick as some actions cannot be shared.

#becomes is exactly what I was looking for, I didn’t know about this
method and it’s not featured in AWDWR 3rd Ed.

Thanks!

On 11 March 2010 14:39, Fernando P. [email protected] wrote:

But it is a Membership object… ?:-/

It’s a Membership indeed, but in the admin section of my app, I don’t
need to recode a specific controller for memberships, they can use the
products_controller which is fine and defining :controller => “products”
won’t do the trick as some actions cannot be shared.

Makes sense.

#becomes is exactly what I was looking for, I didn’t know about this
method and it’s not featured in AWDWR 3rd Ed.

Kewl. Glad to help.
AWDWR is a good book - but it’s not all-encompassing… You need to
get familiar with navigating the Ruby and Rails API documentation to
find the rest of the cool stuff :slight_smile: