Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow scopes on associations #215

Open
forest opened this issue Feb 20, 2014 · 1 comment
Open

Allow scopes on associations #215

forest opened this issue Feb 20, 2014 · 1 comment

Comments

@forest
Copy link

forest commented Feb 20, 2014

I expected scopes on association to work, but they currently don't. Is this a planned feature, or something that is worth me investigating as an enhancement?

Any direction would be appreciated if this enhancement is desired for the project.

class Project
  include Her::Model

  has_many :iterations

  # This works.
  def current_iteration
    iterations.where(scope: :current).first
  end
end

class Iteration
  include Her::Model

  belongs_to :project
  has_many :stories

  scope :done, -> { where(scope: :done) }
  scope :current, -> { where(scope: :current) }
  scope :offset, ->(offset) { where(offset: offset) }
end

project = Project.find(12345)
iteration = project.current_iteration

This is what I want to be able to do, but current is undefined on the Her::Model::Associations::HasManyAssociation

iteration = project.iterations.current
iteration = project.iterations.done.offset(-5)
@remi
Copy link
Owner

remi commented Jun 10, 2014

This is something that would be really useful. This involves rewriting the associations code to make it compatible with the Her::Model::Relation system.

Let me know if this something you’d like to work on! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants