I'm using the model already provide from MerbAuth for an user table,
the id field definition goes like this:

property :id, Serial

But when i use a fixture setting with dm-sweatshop, executing the .gen
method i don't get an auto incremented id.

The same happen with others model which fixtures that i created.

Below the code for the models involve, and the code for the fixtures.
I'm trying this with merb -i and using load("spec/spec_fixtures.rb")
then User.gen or Question.gen

class User

  include DataMapper::Resource

  # properties

  property :id,         Serial

  property :login,      String
  property :first_name, String
  property :last_name,  String

  timestamps :at

  # associations

  has n, :questions
  has n, :answers
  has n, :relevancies
  has n, :interests
  has n, :questions, :through => :interests


end

class Interest

  include DataMapper::Resource

  # properties

  property :user_id,     Integer, :nullable => false, :key => true
  property :question_id, Integer, :nullable => false, :key => true

  timestamps :at

  # associations

  belongs_to :user
  belongs_to :question

end

class Question

  include DataMapper::Resource

  # properties

  property :id,    Serial

  property :user_id, Integer, :nullable => false

  property :title, String, :nullable => false, :length => (1..255)
  property :body,  Text

  timestamps :at

  # associations

  belongs_to :user

  has n, :answers
  has n, :interests
  has n, :users, :through => :interests

end

  User.fix(:anonymous) {{
     :login => 'anonymous',
     :first_name => 'Anonymous',
     :last_name => 'Coward'
   }}

   User.fix {{
     :login =>  first_name = Randgen.first_name,
     :last_name  =>  last_name = Randgen.last_name,
    :login =>  "#{first_name.downcase}#{last_name[0].chr}"
  }}

  Question.fix {{
    :title => /[:sentence:]{4,10}/.gen.gsub(/\.$/, '?'),
    :user_id   => User.pick.id,
    :body   => /[:paragraph:]/.gen
  }}

  Question.fix(:anonymous) {{
    :title  => /[:sentence:]{4,10}/.gen.gsub(/\.$/, '?'),
    :body   => /[:paragraph:]/.gen,
    :user_id   => User.pick(:anonymous).id
  }}

  Interest.fix { DataMapper::Sweatshop.unique {{
    :user     => User.pick,
    :question => Question.pick
  }}}

  ##Population

  User.gen(:anonymous) #create the anonymous user
  5.of { User.gen }     #randomly create 5 users

  10.of { Question.gen }              #create 10 questions with random
users (not the anonymous user)
  10.of { Question.gen(:anonymous) }  #create 10 questions with the
anonymous user

  20.of { Interest.gen }                                  #create 20 interests
  5.of  { Interest.gen(:user => User.pick(:anonymous)) }  #create 5
interests with questions for the anonymous user

Thanks in advance.

-- 
Rafael George

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