On Mon, 8 Mar 2010 15:51:48 -0800 (PST)
bertly_the_coder <[email protected]> wrote:

> Hey Guys,
> 
> if I create two models like so:
> 
>  class Article
>     include DataMapper::Resource
> 
>     has n, :categories, :through => Resource
>   end
> 
>  and
> 
>  class Category
>     include DataMapper::Resource
> 
>    has n, :articles, :through => Resource
> end
> 
> I end up with three tables Articles, Categories and Articles_Category.
> Using Ruby, preferably Sinatra, what object would I need to create to
> correctly insert the corresponding records into all three tables?,
> Which is to say an article that belongs to a certain category

@article = Article.new(:title => 'DataMapper:  Why it rocks')
@article.categories.new(:title => 'DataMapper')
@article.save

-- 
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