Rails - HABTM association, checking exists? of any object in array -


I want to see the existence of any HAABT connection in an array and if someone is present then want to return the truth.

Currently, the only way I can do this is to:

  result = wrong [1,2,3,4]. I If user.parents.exists? (I) Results = End of True Break End  

I tried to pass in an array like this, but I get an exception

  Result = Right if user.parents.exists? ([1,2,3,4]) Include the undefined method for NoMethodError: 1? `: Fixnum  

Is there a better way to do this?

  [1,2,3,4] Injection (wrong) {| Res, i | Res || = User.parents.exists? (I)}  

Too much the same logic, using Syntax Inject just more ruby-ish code.

Update:

Not tested it but it can also work:

  user.parents .exists? (: Id => [1,2,3,4])  

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -