Guest User

Untitled

a guest
May 27th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. class Item
  2. include DataMapper::Resource
  3.  
  4. property :name, String, :key => true
  5. has n, :dosages
  6.  
  7. has n, :producing_recipes, :class_name => 'Recipe',
  8. :child_key => [:product_name]
  9. has n, :consuming_recipes, :class_name => 'Recipe',
  10. :through => :dosages,
  11. :remote_relationship_name => :recipe
  12.  
  13. # Only this one is not working
  14. has n, :derivatives, :class_name => 'Item',
  15. :through => :consuming_recipes,
  16. :near_relationship_name => :product
  17. has n, :materials, :class_name => 'Item',
  18. :through => :producing_recipes,
  19. :remote_relationship_name =>
  20. :ingredients,
  21. :child_key => [:product_name]
  22. end
  23.  
  24. class Recipe
  25. include DataMapper::Resource
  26.  
  27. property :id, Serial
  28. belongs_to :product, :class_name => 'Item',
  29. :child_key => [:product_name]
  30. has n, :dosages
  31. has n, :ingredients, :class_name => 'Item',
  32. :through => :dosages,
  33. :remote_relationship_name => :item
  34. end
  35.  
  36.  
  37. class Stack
  38. include DataMapper::Resource
  39. property :id, Serial
  40. property :type, Discriminator
  41. property :quantity, Integer
  42. property :item_name, String
  43.  
  44. belongs_to :item
  45. end
  46.  
  47. class Dosage < Stack
  48. property :recipe_id, Integer
  49. belongs_to :recipe
  50. end
Add Comment
Please, Sign In to add comment