# Models...revisited

**URL:** <https://www.ruby-forum.com/t/models-revisited/114595>\
**Category:** Engines\
**Created:** [September 17, 2007, 5:48am UTC](https://www.ruby-forum.com/t/models-revisited/114595 "2007-09-17T05:48:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![subimage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@subimage](https://www.ruby-forum.com/u/subimage)\
**Post date:** [September 17, 2007, 5:48am UTC](https://www.ruby-forum.com/t/models-revisited/114595/1 "2007-09-17T05:48:08Z")

</div>

Reviving a 2 year old thread, how is everyone extending their models in  
engines these days?

I’m attempting to move Substruct to a module system as described here:  
[http://www.ruby-forum.com/topic/51339](http://www.ruby-forum.com/topic/51339)

…but I’m getting a ton of errors like this one:

“undefined method `has\_and\_belongs\_to\_many’ for Substruct::Tag:Module”

So what good is that method if you have to redeclare the associations in  
the class, and not within the module itself?

Any ideas or tricks that people are using to get around this? Copying /  
pasting models into app/models to extend is getting tiresome, but this  
workaround seems pretty hackish as well.

---

<div class="post-metadata">

**Author:** ![subimage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@subimage](https://www.ruby-forum.com/u/subimage)\
**Post date:** [September 20, 2007, 9:36am UTC](https://www.ruby-forum.com/t/models-revisited/114595/2 "2007-09-20T09:36:51Z")

</div>

Peter B. wrote:

> On Mon, Sep 17, 2007 at 05:48:08AM +0200, Subimage Interactive wrote:  
> require\_dependency RAILS\_ROOT + “vendor/plugin/my\_plugin/app/models/foo”
> 
> class Foo \< ActiveRecord::Base
> 
> # extend here
> 
> end

Many thanks…syntax was a bit off, but easily corrected.

require\_dependency RAILS\_ROOT +  
“/vendor/plugins/substruct/app/models/order”

class Order \< ActiveRecord::Base  
def promotion\_code  
if self.promotion  
return self.promotion.code  
else  
return “W001”  
end  
end

end

---

<div class="post-metadata">

**Author:** ![subimage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@subimage](https://www.ruby-forum.com/u/subimage)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/models-revisited/114595/3 "2007-09-17T13:24:25Z")

</div>

On Mon, Sep 17, 2007 at 05:48:08AM +0200, Subimage Interactive wrote:

> So what good is that method if you have to redeclare the associations in  
> the class, and not within the module itself?
> 
> Any ideas or tricks that people are using to get around this? Copying /  
> pasting models into app/models to extend is getting tiresome, but this  
> workaround seems pretty hackish as well.

See [Extending models from engines - Engines Development - Ruby-Forum](http://www.ruby-forum.com/topic/98597). This turned out not to work  
100%,  
as we found out in [Problem with assocations - Engines Development - Ruby-Forum](http://www.ruby-forum.com/topic/99211)

Short and simple:

In app/models/foo.rb:

require\_dependency RAILS\_ROOT + “vendor/plugin/my\_plugin/app/models/foo”

class Foo \< ActiveRecord::Base

# extend here

end

Hope this helps,  
Peter B.  
Solide ICT - [http://www.solide-ict.nl](http://www.solide-ict.nl)
