# How to dynamically buid relationships between models?

**URL:** <https://www.ruby-forum.com/t/how-to-dynamically-buid-relationships-between-models/61196>\
**Category:** Engines\
**Created:** [May 21, 2006, 1:50pm UTC](https://www.ruby-forum.com/t/how-to-dynamically-buid-relationships-between-models/61196 "2006-05-21T13:50:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [May 21, 2006, 1:50pm UTC](https://www.ruby-forum.com/t/how-to-dynamically-buid-relationships-between-models/61196/1 "2006-05-21T13:50:45Z")

</div>

Hi all

I’m trapped with the following problem.

I’d like to work with the UserEngine engine. Every user has let’s say a  
Profile model. So they have a 1:1 relationship.

Now I should declare this relationship in both models. But where do I  
have to declare it exactly in the User model? I see they are working  
somehow with modules in the engine’s lib dir, but how does this work  
exactly? I’m quite confused… :-/

Thanks for explanation of this topic. 🙂  
Joshua

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [May 21, 2006, 11:42pm UTC](https://www.ruby-forum.com/t/how-to-dynamically-buid-relationships-between-models/61196/2 "2006-05-21T23:42:20Z")

</div>

For information about adding application-specific functionality to  
models which are supplied by engines, please read the engines’ README  
(in the engines plugin), and this:  
[http://rails-engines.org/wiki/pages/Why+Models+Don’t+Act+Like+Controllers](http://rails-engines.org/wiki/pages/Why+Models+Don%27t+Act+Like+Controllers)

- james

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [May 26, 2006, 2:24pm UTC](https://www.ruby-forum.com/t/how-to-dynamically-buid-relationships-between-models/61196/3 "2006-05-26T14:24:09Z")

</div>

#if forum /\* May 21, 01:50 \*/

> exactly? I’m quite confused… :-/
> 
> Thanks for explanation of this topic. 🙂  
> Joshua  
> #endif /\* removed\_email\_address@domain.invalid \*/

if i understand you correctly, you want to augment the User model with  
some extra relationships? If thats the case, then something like the  
following might help you:

I have a model called “Person”, that looks something like this:

app/models/person.rb:

class Person \< User  
has\_many :settings, :class\_name =\> “UserSetting” do  
def default\_users\_acl\_name  
acl\_name = find\_by\_property(“DefaultACL”).value  
end  
end  
end

The “User” class comes from  
vendor/plugins/login\_engine/app/models/user.rb

Then, whenever i want to use my extra functionality to the User model i  
just go via People instead:

p = Person.find\_by\_login(“admin”)  
p.settings  
[…]

p = Person.find(1)  
etc, etc.

This way, i can let user/login engine do all its clever stuff, but i  
dont have to make any changes to that code base

does that help?

-v

P.S. dont be offended by the quote, its randomly generated

–  
keys: [http://codex.net/gpg.asc](http://codex.net/gpg.asc)

There are only two truly infinite things, the universe and stupidity.  
And I am unsure about the universe.  
– Albert Einstein
