Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Permission < ActiveRecord::Base
- belongs_to :source, :polymorphic => true
- belongs_to :right, :polymorphic => true
- acts_as_double_polymorphic_join(
- :sources => [:projects, :purchase_orders, :grants],
- :rights => [:languages, :distributions, :media, :editions]
- )
- end
- class CreatePermissions < ActiveRecord::Migration
- def self.up
- create_table :permissions do |t|
- t.references :source, :polymorphic => true
- t.references :right, :polymorphic => true
- t.timestamps
- end
- end
- def self.down
- drop_table :permissions
- end
- end
- >> p = Project.find :first
- => #<Project id: 941207533, client_id: 661067193, code: "08-210", title: "California History", series: nil, isbn: "123456789-0", copyright: "2009", number: nil, author: "Sean Schofield", level: "8", imprint: nil, edition: nil, acronym: nil, product_type: 1, created_at: "2008-05-01 09:44:50", updated_at: "2008-05-01 09:44:50">
- >> p.languages
- => [#<Language id: 449228226, name: "English + 1", created_at: "2008-05-01 09:44:50", updated_at: "2008-05-01 09:44:50">]
- >> p.media
- => [#<Media id: 548512980, name: "Print", created_at: "2008-05-01 09:44:50", updated_at: "2008-05-01 09:44:50">, #<Media id: 349762400, name: "CD-Rom", created_at: "2008-05-01 09:44:50", updated_at: "2008-05-01 09:44:50">]
- >> l = Language.find 449228226
- => #<Language id: 449228226, name: "English + 1", created_at: "2008-05-01 09:44:50", updated_at: "2008-05-01 09:44:50">
- >> l.projects
- => [#<Project id: 941207533, client_id: 661067193, code: "08-210", title: "California History", series: nil, isbn: "123456789-0", copyright: "2009", number: nil, author: "Sean Schofield", level: "8", imprint: nil, edition: nil, acronym: nil, product_type: 1, created_at: "2008-05-01 09:44:50", updated_at: "2008-05-01 09:44:50">]
Add Comment
Please, Sign In to add comment