I have one to many relation between folders and docs tabels. I want to look whether a folder includes a doc like:
q = Doc.new(blabla)
folder.docs.inludes?(q)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re creating a new Doc like that, irrespective of the content of the Doc, it will never be identical to any other Doc in the database (as far as include? is concerned) as the Doc’s will have differing id’s/object instance hashes.
If you wanted to be able to compare Doc’s based off of content rather than the actual record (referenced by id), you could eql? (==) – see here: http://ruby-doc.org/core-1.9.3/Object.html#method-i-eql-3F. I would not recommend doing that though.
I would re-think your solution here ideally. What are you trying to check, to see if a folder contains a document by a particular name?
If you get a non-nil result, you have a doc in the folder with the name ‘blabla’, if it’s nil you don’t.