hi all, i'm new to datamapper and i can't figure out how associations
naming works.
consider the following model (just an example):

class Author
  include DataMapper::Resource
  property :id, Serial
  property :name, String
  has n, :books,
    :through => Resource,
    :class_name => "Book",
    :child_key => [:book_id]
end

class Book
  include DataMapper::Resource
  property :id, Serial
  property :name, String
  has n, :authors,
    :through => Resource,
    :class_name => "Author",
    :child_key => [:author_id]
end

DataMapper::auto_migrate!

that works fine, so that i can run this:

author = Author.create(:name => 'john')
book = Book.create(:name => 'cooffe')
book1 = Book.create(:name => 'milk')

author.books << book
author.books << book1

author.save
book.save
book1.save

author.books.each { |e| puts e.name }

ok. now comes the problem. i want the association in class Author to
be called something else then 'books', say 'foobar', so that i can
run:

author.foobar << book

a natural approach, from what i can infer from documentation, would be
to pass the desidered name as a symbol to method #has inside class
Author definition, like this:

class Author
  has n, :foobar, # <- HERE
    :through => Resource,
    :class_name => "Book",
    :child_key => [:book_id]
end

that sadly doesn't work. instead it yields this error:

ArgumentError: +options[:links]+ entry nil not supported

which i find not very informative.

would you please provide some insight?
thanks



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