paulelliott/fabrication — Issue #67: Using callbacks - help needed
Author: afriqs
Created: 2011-10-10 13:16:42+00:00
State: open

Hi,

Then follow my model declarations:

```
class Association < ActiveRecord::Base
attr_accessible :title
has_many :members, :foreign_key => "asso_id", :dependent => :destroy

after_create :create_member

private

def create_member
self.members.create!({:name => "MyRealName"})
end
end

class Member < ActiveRecord::Base
attr_accessible :name

belongs_to :asso, :class_name => "Association", :dependent => :delete
end
```

And the fabricators :

```
Fabricator(:association) do
title "MyAsso"
after_create do |asso|
Fabricate(:member, :asso => asso)
end
end

Fabricator(:member) do
name "MyName"
asso { Fabricate(:association) }
end
```

I surely missed something, but here are the Rspec issues I have:

```
Failure/Error: let(:asso) { Fabricate(:association) }
ActiveRecord::UnknownAttributeError:
unknown attribute: asso_id
```

Hope somebody can help me ;)

Cheers, Alex.