This sounds counter intuitive, but what I think you actually want is

class Album
  belongs_to :media_type
end

class MediaType
  has n, :albums
end

In DataMapper, the belongs_to denotes which model has the foreign key.
 So in this case, you want each album to have a reference to the
correct media type, so it needs the belongs_to.

The reason nothing happened in your second example is that the has 1
on the albums set up a belongs_to on the MediaType.  In DataMapper,
foreign keys are required by default (though this can be turned off)
so your media types weren't saving as they needed an album foreign key

Regards
Jon

On 20 September 2010 22:20, cootcraig <[email protected]> wrote:
>
> A resource class Album will reference with "has 1" a table MediaType.
> I want to populate the table MediaType with rows, if they don't exist.
>
> 2 snippets:
>
> http://snippie.net/snip/904775f2
>
> The has 1 is left off and 4 rows are inserted into table MediaType.
>
> http://snippie.net/snip/2faec272
> The has 1 is included and no rows are inserted into table MediaType.
>
> rvm use
> => ruby-1.9.2-p0 [ i386 ]
> gem list
> data_mapper (1.0.2)
>
> Can someone enlighten me?  I hope you can follow this.

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to