Relationships with remote objects

Hi guys,

I’m having an issue establishing a has_many and/or belongs_to
relationship between two of my models.
One of them is ‘local’ if you like (called site), i.e. standard model
in local db, the other is a RESTful resource (called audit), defined
using the self.site method. I have checked and the audit class URL is
providing a ‘site_id’ field as expected.

When adding a ‘belongs_to :site’ reference to audit, I get the
following error:

‘app/app/models/audit.rb:3: undefined method `belongs_to’ for
Audit:Class (NoMethodError)’

Are relationships like this not possible?

Thanks again chaps,

Paul

Paul T. wrote in post #1007298:

I’m having an issue establishing a has_many and/or belongs_to
relationship between two of my models.
One of them is ‘local’ if you like (called site), i.e. standard model
in local db, the other is a RESTful resource (called audit), defined
using the self.site method. I have checked and the audit class URL is
providing a ‘site_id’ field as expected.

When adding a ‘belongs_to :site’ reference to audit, I get the
following error:

‘app/app/models/audit.rb:3: undefined method `belongs_to’ for
Audit:Class (NoMethodError)’

Are relationships like this not possible?

AFAIK ActiveResource doen’t provide support for relations to other
models.

It is actually a much more complex issue than it might appear on the
surface to implement such relations. When ActiveRecord deals with
relationships it uses database transactions to provide data consistency
and durability. When dealing with associations to remote data stores
this become exceedingly more complicated.

To get a better feel for what I’m talking about read up on ACID:

http://en.wikipedia.org/wiki/ACID

paulo <[email protected]…> writes:

When adding a ‘belongs_to :site’ reference to audit, I get the

Looks like you’re using a staright Class or ActiveRecord rather than
ActiveResource. Make sure your audit class looks something like:

class Audit < ActiveResource::Base
self.site = “http://www.myawesomesite.com/
end