tags:

views:

29

answers:

0

I am beginner to datamapper and I am having trouble resolving the following problem.

I am trying to create two tables with 1 to many relationship.

Table 1: with a composite key of (A, B, C)
Table 2: with a composite key of (A, B, C, D)

    With A, B, C foreign key constraint to Table 1.
    A, B, C, D make a composite key for table 2.

This is to enable us to add one or more (D =1, 2,3,..) records for (A = 1,B=1,C =1) record in table1.
Also add one or more (D=1,2,3,..) records for (A=2, B=2, C=2) record in table 1.

The code I have so far looks something like this. But this does provide the desired key constraints I am looking for.

In table two, I am trying to make id serial and d_key part of the composite child key without any success.
OR
I would like to just make a_key,b_key,c_key and d_key composite keys for table 2.
Appreciate any and help.
Thanks
Jon D.


class TableOne
include DataMapper::Resource
property :a_key, integer, :key => true
property :b_key, integer, :key => true
property :c_key, integer, :key => true

property :updated_at, DateTime
property :overall_total, Integer
property :display_total, String

has n, :table_two, :model=> TableTwo,
:parent_key => [:a_key, :b_key, :c_key],
:child_key => [:a_key, :b_key, :c_key, :d_key]

end
class TableTwo
include DataMapper::Resource

property :id Integer, :key =>true
property :d_key, Integer
property :count, Integer
property :total, Integer
property :updated_at, DateTime

belongs_to :table_one, :model=> TableOne,
:parent_key => [:a_key, :b_key, :c_key],
:child_key => [:a_key, :b_key, :c_key, :d_key]

end