I have a migration file written as such:
class Character < ActiveRecord::Migration
def change
create_table :character_attributes do |t|
t.string :character_name
t.boolean :attr1, default: false, null: false
t.boolean :attr2, default: false, null: false
t.boolean :attr3, default: false, null: false
t.boolean :attr4, default: false, null: false
t.boolean :attr5, default: false, null: false
t.boolean :attr6, default: false, null: false
t.boolean :attr7, default: false, null: false
t.timestamps null: false
end
end
end
Essentially, each character has 7 possible attributes yet can only have one (in other words, if one of the seven fields is true, the rest will be false).
Other discussions (i.e. Rails 4.x how to query boolean value with activerecord?) query from the model. But can you write the code as such so that rails queries through the multiple fields/attributes within the object? i.e.
Character.find_by_character_name("Jack").where(:attributes => true)
Also, I understand redesigning the schema can be an option, but for now I'd just like to know if the query can be done.
statusenum column would do the trick: api.rubyonrails.org/v4.1.0/classes/ActiveRecord/Enum.html