ActiveRecord through Drb: problem with ids

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...

···

ara.t.howard@noaa.gov wrote:

On Fri, 25 Aug 2006, Philippe Lang wrote:

obj = DRbObject.new(nil, 'druby://localhost:9000')

g = obj.find(1)
puts "#{g.id} | #{g.name}"
g.flowers.each do |f|
puts "#{f.id} | #{f.garden_id} | #{f.name}"
end
------------------------------------------------------

... I get:

------------------------------------------------------
ar_client.rb:8: warning: Object#id will be deprecated; use
Object#object_id 67884862 | garden1
ar_client.rb:10: warning: Object#id will be deprecated; use
Object#object_id 67882632 | 1 | flower1
ar_client.rb:10: warning: Object#id will be deprecated; use
Object#object_id 67880122 | 1 | flower2
------------------------------------------------------

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

---------------
Philippe Lang
Attik System

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

···

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

ara.t.howard@noaa.gov wrote:

On Fri, 25 Aug 2006, Philippe Lang wrote:

obj = DRbObject.new(nil, 'druby://localhost:9000')

g = obj.find(1)
puts "#{g.id} | #{g.name}"
g.flowers.each do |f|
puts "#{f.id} | #{f.garden_id} | #{f.name}"
end
------------------------------------------------------

... I get:

------------------------------------------------------
ar_client.rb:8: warning: Object#id will be deprecated; use
Object#object_id 67884862 | garden1
ar_client.rb:10: warning: Object#id will be deprecated; use
Object#object_id 67882632 | 1 | flower1
ar_client.rb:10: warning: Object#id will be deprecated; use
Object#object_id 67880122 | 1 | flower2
------------------------------------------------------

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...