I have two tables, nodes
and terms
.
The relevant fields in nodes
are: nid
(primary key) and value
In terms
, they are: value
, tid
, and nid
, where value
and tid
together are the primary key and nid
is a foreign key referencing nodes.nid
.
I want to add records to terms
. I have the tid
and nid
, and the value
I want to pull from the corresponding node
- e.g. look up the value
for a given nid
in node
and then put that as the value
in terms
.
A way to do this in SQL might be:
INSERT INTO terms(tid, nid, value)
values(mytid, mynid, (
select value from nodes where nid=mynid
));
Could somebody help me do this with DataMapper?
class Node
include DataMapper::Resource
property :nid, Serial, :key => true
property :value, Integer
end
class Term
include DataMapper::Resource
property :tid, Integer, :key => true
# how do I define nid and value?
end
# and then what do I give to Term.new or Term.create and how?
If anyone could point me to a good tutorial of DataMapper as well, I'd appreciate it. I've been using their online docs, but I've found the situations I find myself in are rarely covered there.