daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest May 16th, 2018 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Permission < ActiveRecord::Base
  2.   belongs_to :source, :polymorphic => true
  3.   belongs_to :right, :polymorphic => true
  4.  
  5.   acts_as_double_polymorphic_join(
  6.     :sources => [:projects, :purchase_orders, :grants],
  7.     :rights => [:languages, :distributions, :media, :editions]
  8.   )
  9. end
  10.  
  11.  
  12.  
  13. class CreatePermissions < ActiveRecord::Migration
  14.   def self.up
  15.     create_table :permissions do |t|
  16.       t.references :source, :polymorphic => true
  17.       t.references :right, :polymorphic => true
  18.       t.timestamps
  19.     end
  20.   end
  21.  
  22.   def self.down
  23.     drop_table :permissions
  24.   end
  25. end
  26.  
  27. >> p = Project.find :first
  28. => #<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">
  29. >> p.languages
  30. => [#<Language id: 449228226, name: "English + 1", created_at: "2008-05-01 09:44:50", updated_at: "2008-05-01 09:44:50">]
  31. >> p.media
  32. => [#<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">]
  33.  
  34.  
  35. >> l = Language.find 449228226
  36. => #<Language id: 449228226, name: "English + 1", created_at: "2008-05-01 09:44:50", updated_at: "2008-05-01 09:44:50">
  37. >> l.projects
  38. => [#<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">]
RAW Paste Data
Top