Local variable override field in query

Hi everyone

I have table with column “metadata”, variable metadata and the query

metadata contains hash
when I run this query:

scope = scope.where { metadata.contain(level: metadata[:level]) }

I get error:

undefined method `contain' for an instance of Hash

metadata overrides table of column, how can i fix it without renaming variable?

It would be helpful to know the execution context of this code sample. This looks like its probably Repository code.

You could write a Relation method like so:

def with_metadata(**metadata)
  where(self[:metadata].contain(**metadata))
end

within a Repository, you will need to explicitly use the table helper:

scope = scope.where(table_name[:metadata].contain(level: metadata[:level]))

If you’re not in the context of either a Relation or a Repository, well this code belongs there instead.

scope = scope.where { scope[:metadata].contain(**metadata) }

It is a context of repository. Thank you!