Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to model differing criteria?
    text
    copied!<p>I need to be able to match prospective owners to abandoned animals based on varying criteria and locations.</p> <p>The owner will have a particular criteria set. Animal type = "dog", breed = "Labrador Retriever", age will need to be between 1 and 5, sex = male, and so on...</p> <p>The animal will also have a particular criteria set. The animal type = "Dog", age = 3, sex = male, breed = "Chihuahua".</p> <p>The animal could also be: type = "Cat", age = "12", sex = female, breed = "Tiger".</p> <p>I also have a "Location" model for both the owner and the animal (polymorphic) that contains the information related to the location of either the animal or the owner.</p> <p>So that part is easy...</p> <p>The hard part (at least for me) is when I need to specify different criteria for different animal types. So an animal of type = "dog" may have a criteria of "can fetch?" whereas an animal of type cat may have a criteria of "de-clawed?" and a animal of type "fish" may have criteria of "pattern" with multiple options of ["speckled", "striped", "plain"].</p> <p>What I have now is an "animal" model with the generic animal information (age, sex, breed), then I have a breeds model with the various breeds per animal type, but I can't figure out how to abstract out the criteria that differs between the animal types.</p> <p>Again, this is just an analogy because I don't think my actual problem will make any sense to anyone else. What I need is just some pointers in the right direction, maybe a link or two. I just can't seem to work out how to make this happen in Rails without creating a separate table for each criteria set, as in dog_criteria, cat_criteria, fish_criteria, and so on...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload