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

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

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

http://guides.rubyonrails.org/association_basics.html

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.

http://guides.rubyonrails.org/association_basics.html

@Michael, perhaps we should work in shifts.

Colin

:smiley:

Michael Pavling wrote in post #1063859: