我正在为一个慈善机构开发一个rails应用程序,该慈善机构为Families、Fundraisers以及慈善组织本身接受群众资助的捐款。现在,捐款是属于家庭的&使用多态性的募捐者,但我不知道如何为慈善机构筹款。
我应该为慈善机构做一个捐赠的榜样吗?这对我来说是个糟糕的架构,因为它将是一个单一的数据库记录。
接受慈善捐款的最佳方式是什么?
这是我的捐赠模式:
#app/models/donation.rb
class Donation < ActiveRecord::Base
has_secure_token
belongs_to :family, via: :recipient
belongs_to :fundraiser, via: :recipient谢谢!
发布于 2015-08-30 23:54:40
在您的迁移过程中,您应该做如下的事情
class Donations < ActiveRecord::Migration
def change
create_table :donations do |t|
...
t.integer :something_id # this is the record id of something
t.string :something_type # this is the model name like family or fundraiser
t.timestamps
end
end
end现在在你的模型里
class Donation < ActiveRecord::Base
belongs_to :something, polymorphic: true
end
# repeat this in all the models that can use this polymorphic association
class Family < ActiveRecord::Base
has_many :donations, as: :something
end我希望这会有所帮助。
快乐黑客
https://stackoverflow.com/questions/32301469
复制相似问题