App Engine Jruby DataMapper列表属性

时间:2009-10-10 10:35:59

标签: ruby google-app-engine jruby datamapper

如何在Google AppEngine上的Jruby上使用list / array作为DataMapper中的属性?

1 个答案:

答案 0 :(得分:5)

这将像has..and..belongs..to..many一样工作,没有连接表......

class Person
  include DataMapper::Resource
  property :id,          Serial
  property :name,        String, :nullable => false
  property :project_ids, List
  timestamps :at
  # project should be flagged as archived, not deleted
  def projects
    Project.all(:id => project_ids)
  end
end

class Project
  include DataMapper::Resource
  property :id,          Serial
  property :name,        String, :nullable => false
  property :archived,    Boolean, :default => false
  # the join table is bolted onto the person model
  def people
    Person.all(:project_ids => id)
  end
end