0

I have a model TestRun that has an array entry :machine_ids that is an array of integers. How will I be able to call find with conditions so that I can find the specific TestRun entry whose field :machine_ids has a specific array entry mid and a :status "Running".

This is a rough outline of what I want. I do not know how to format the conditions for finding if the array contains mid.

cur_testrun = TestRun.find(:first, :conditions => {:machine_ids => mid, :status => "Running"})

1 Answer 1

0

The array will serialize into YAML for storage in your database. Serialized data doesn't lend itself to easy or efficient querying.

As suggested in the question & answer below, you could try normalize the schema a little. Alternatively you're left with the SQL 'like' query which won't be fun to write if your matching gets complex.

Rails active record query, serialized array

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.