Guest User

Untitled

a guest
Jun 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. class Image < ActiveRecord::Base
  2. has_many :custom_fields
  3. # has a name column
  4. end
  5.  
  6. class CustomField < ActiveRecord::Base
  7. belongs_to :field, :polymorphic => true
  8. # has only IDs
  9. end
  10.  
  11. class StringField < ActiveRecord::Base
  12. has_one :custom_field, :as => :field
  13. # has a value column
  14. end
  15.  
  16. Image.find(:join => {:custom_fields=>:field}, :conditions => {"custom_fields.name"=>name, "custom_fields.field.value"=>value})
Add Comment
Please, Sign In to add comment