Skip to content

Improve 'where' compatibility with ActiveRecord #5

@norchow

Description

@norchow

The current implementation returns an Array, which is not queryable (in comparison with ActiveRecord::Relation)

Possible implementation:

module Model
  def self.where(*args)
    //Check if args is a hash and filter values
    filtered_values = all
    StaticModelArray.new(filtered_values)
  end
end

class StaticModelArray < Array
  def initialize(values)
    @values = values
  end

  def find(id)
    @values.find{|v| v.id == id.to_d}
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions