# Overriding Models

**URL:** <https://www.ruby-forum.com/t/overriding-models/76665>\
**Category:** Engines Development\
**Created:** [March 4, 2006, 12:18pm UTC](https://www.ruby-forum.com/t/overriding-models/76665 "2006-03-04T12:18:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhutter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@mhutter](https://www.ruby-forum.com/u/mhutter)\
**Post date:** [March 4, 2006, 12:18pm UTC](https://www.ruby-forum.com/t/overriding-models/76665/1 "2006-03-04T12:18:37Z")

</div>

Hi list.

I know that it is currently hard to override anything in the model  
classes of an Engine. What about the following:

Engines includes the file RAILS\_ROOT/app/components/engine\_models.rb  
after the last model require. In this file, you can have code like:

class MyModel  
has\_many :foo  
end

So you can mix in code there.

Would this work, James?

Regards,

Manuel

---

<div class="post-metadata">

**Author:** ![mhutter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@mhutter](https://www.ruby-forum.com/u/mhutter)\
**Post date:** [March 6, 2006, 5:05pm UTC](https://www.ruby-forum.com/t/overriding-models/76665/2 "2006-03-06T17:05:44Z")

</div>

I’m not very keen on putting models in files other than  
\<model\_name\>.rb, since this fits best with Rails’ own scheme and will  
work with the auto-dependency loading too. The ‘best practice’ at the  
moment is to only provide stub models in your engine, and use meta  
programming along with modules to include functionality. Take a look  
at the login/user engines’ User model classes for an example of this.

The advantage of doing it this way is that an end-user-developer can  
override methods by creating their own model class, adding the  
‘include’ lines and then redefining any methods that they want. It’s  
not perfect, but it’s literally only a couple of lines more than the  
controlller/helper mixing.

- james

On 3/4/06, Manuel H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> engine-developers mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rails-engines.org/listinfo.cgi/engine-developers-rails-engines.org](http://lists.rails-engines.org/listinfo.cgi/engine-developers-rails-engines.org)

–

- J \*  
~
