Modeling one way associations

Hi

I am working on a project where I have a Process object that references
a Node object. I have tried adding a node_id column in the Process
table and created an has_one relationship in the Process model.

When trying Process.node.create(@attr) am getting an error as the sql is
trying to update the process_id column in the Node table. I dont want
to add a process_id column in the node table as most nodes will not
refer to a process (ie one way association between process and node).

Any ideas?

Cheers

jason

On 9 June 2012 16:45, Jason W. [email protected] wrote:

I am working on a project where I have a Process object that references
a Node object. I have tried adding a node_id column in the Process
table and created an has_one relationship in the Process model.

Change that relationship definition to a belongs_to rather than a
has_one.

On 9 June 2012 16:45, Jason W. [email protected] wrote:

Hi

I am working on a project where I have a Process object that references
a Node object. I have tried adding a node_id column in the Process
table and created an has_one relationship in the Process model.

If you have node_id in Process then you want process belongs_to node.
Have a look at the Rails Guide on ActiveRecord Associations for more
information.

Colin

On 9 June 2012 17:35, Michael P. [email protected] wrote:

On 9 June 2012 16:45, Jason W. [email protected] wrote:

I am working on a project where I have a Process object that references
a Node object. I have tried adding a node_id column in the Process
table and created an has_one relationship in the Process model.

Change that relationship definition to a belongs_to rather than a has_one.

Active Record Associations — Ruby on Rails Guides

@Michael, perhaps we should work in shifts.

Colin

Michael P. wrote in post #1063859:

On 9 June 2012 17:51, Colin L. [email protected] wrote:

@Michael, perhaps we should work in shifts.

Colin

:smiley:

Thanks fellas - that did the trick :slight_smile:

On 9 June 2012 17:51, Colin L. [email protected] wrote:

@Michael, perhaps we should work in shifts.

Colin

:smiley: