Hello! We have some associations that have functional dependencies among 
one another, and I'd love a mechanism that let me reflect this relationship 
in code. Here is an analogous example:

class User
  many_to_one :site
  dataset_module do
    def active; where(deleted_at: nil); end
  end
end

class Site
  one_to_many :users
  one_to_many :active_users, class: 'User' { |u| u.active }
end

with this model, if I run

site = Site.create
site.active_users # it's empty
site.add_user(name: 'ursula')
site.users # the newly-added ursula
site.active_users # still empty

The `active_users` association is still empty, because it's cached from my 
initial call, and the code does not know that I've added a new user. I'd 
like to propose a :depends_on option to associations to allow marking these 
dependencies explicitly in order to enable dependent associations to 
automatically clear if the association they depend on is modified. E.g.:

class Site
  one_to_many :users
  one_to_many :active_users, class: 'User', depends_on: :users { |u| 
u.active }
end

which would give us:

site = Site.create
site.active_users # it's empty
site.add_user(name: 'bob')
site.users # the newly-added bob
site.active_users # bob is also here, because the association is re-fetched 
since it was cleared from the cache when bob was added above

Thoughts? I've started playing around with a patch [1]; I can run with it 
if this is useful and desirable.

[1]: 
https://github.com/uhoh-itsmaciek/sequel/commit/8a353b1e3329b4045e529fa1239afcb892de8035

Thanks,
Maciek

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to