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)’
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: