# Re: ActiveRecord through Drb: problem with ids

**URL:** <https://www.ruby-forum.com/t/re-activerecord-through-drb-problem-with-ids/66493>\
**Category:** Ruby\
**Created:** [August 26, 2006, 11:42am UTC](https://www.ruby-forum.com/t/re-activerecord-through-drb-problem-with-ids/66493 "2006-08-26T11:42:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [August 26, 2006, 11:42am UTC](https://www.ruby-forum.com/t/re-activerecord-through-drb-problem-with-ids/66493/1 "2006-08-26T11:42:33Z")

</div>

removed\_email\_address@domain.invalid wrote:

> > * * *
> 
> certain methods are treated specially by drb. it was a  
> mistake for rails to override Object#id for exatly this kind  
> of scenario - many peice of code require it.
> 
> you need to do something like
> 
> class \<\< ActiveRecord  
> alias “id\_\_”, “id”  
> end

Hi,

Thanks for your answer. I see now where the problem comes from, but your  
“trick” is apparently not sufficient. The code…

class Garden \< ActiveRecord::Base  
include DRbUndumped  
has\_many :flowers  
alias :id\_\_ :id  
end

class Flower \< ActiveRecord::Base  
include DRbUndumped  
belongs\_to :garden  
alias :id\_\_ :id  
End

… Still does not work…

---

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [August 26, 2006, 1:40pm UTC](https://www.ruby-forum.com/t/re-activerecord-through-drb-problem-with-ids/66493/2 "2006-08-26T13:40:30Z")

</div>

On Aug 25, 2006, at 9:23 AM, Philippe L. wrote:

> > > * * *
> > > 
> > > Object#object\_id 67880122 | 1 | flower2  
> > > end  
> > > end
> 
> class Flower \< ActiveRecord::Base  
> include DRbUndumped  
> belongs\_to :garden  
> alias :id\_\_ :id  
> End
> 
> … Still does not work…

Hey Philip-

```
I have dealt alot with ActiveRecord over drb, I use it in this

```

plugin for rails[1] . The way around this is to use a different  
notation to get the id of the AR object. So with your client example  
change it to this and you will be fine:

#!/usr/local/bin/ruby  
require ‘drb’

DRb.start\_service()  
obj = DRbObject.new(nil, ‘druby://localhost:9000’)

g = obj.find(1)  
puts “#{g[:id]} | #{g.name}”  
g.flowers.each do |f|  
puts “#{f[:if]} | #{f[:id]} | #{f.name}”  
end

```
So by using arinstance[:id] instead of arinstance.id you will avoid

```

this problem all together.

Cheers-  
-Ezra

[1] [http://backgroundrb.rubyforge.org](http://backgroundrb.rubyforge.org)
