Skip to content

Suggestions/Questions #58

@fatkodima

Description

@fatkodima

I had an idea for a similar gem in my TODO list, but after this week's RubyWeekly I noticed there is one already. So I will invest some effort into improving it, if you don't mind 😄

  1. Wdyt on supporting scopes as belongs_to association names:
class Answer < ActiveRecord::Base
  belongs_to :question
  acts_as_sequenced scope: :question
end

It looks more natural to me, than specifying column names and simplifies the setup when belongs_to is polymorphic.

  1. Support sharing scopes. For example, like on GitHub: both issues and pull requests are scoped to a repository.
  2. Why testing of MySQL was removed from this gem?
  3. Currently, when calculating the next sequential id, the whole table is locked (PostgreSQL only 🤔?)
    def lock_table
    if postgresql?
    record.class.connection.execute("LOCK TABLE #{record.class.table_name} IN EXCLUSIVE MODE")
    end
    end

    Whole table locks are very heavyweight and dangerous (see lock queueing in PostgreSQL) and are really not needed. I suggest locking only the parent record (if :scope is for parent record) using SELECT ... FOR UPDATE (https://api.rubyonrails.org/v5.2/classes/ActiveRecord/Locking/Pessimistic.html), this should be enough.
  4. README states that the scope option can be any attribute (not only the foreign key of an associated parent object). But what is the use case for this?

If these changes are OK, I will start implementing them one by one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions