Newbie Neo4j.rb (v8.2.1) gem user here trying to figure out how to handle subclassing ActiveRel properly...
I have one relationship type called HasAccount that I then subclass in others, i.e. OwnsAccount < HasAccount. I have relationships defined in my model like this:
has_many :out, :accounts, rel_class: :HasAccount
has_many :out, :owned_accounts, rel_class: :OwnsAccount
has_many :out, :managed_accounts, rel_class: :ManagesAccount
My intent is that whenever I create an OwnsAccount or ManagesAccount relationship for a node, they'd also be accessible via my_node.accounts (i.e. the superclass' has_many).
Am I approaching this wrong? I've tried every which way and that shy of ditching HasAccount entirely and definining an accounts method that merges owned_accounts and managed_accounts...
I don’t think that subclasses
ActiveRelclasses would help, unfortunately (probably you’ve found that ;) ).If you didn’t have an
ActiveRelclass you can specify multiple types (I don’t remember if we implementedtype: [:OWNS_ACCOUNT, :MANAGES_ACCOUNT]but you could certainly do eithertype: "OWNS_ACCOUNT|MANAGES_ACCOUNT”’ortype: false/type: :any).If you need to have logic on your relationships then you would need
ActiveRel. You can havetype :anyon theActiveRelclass I think, but I don’t know how you’d have separateowned_accounts/managed_accountsassociations in that case (I thinktypeandrel_classare mutually exclusive, but it might be work trying).Really, probably, we should allow for
rel_class: [:OwnsAccount, :ManagesAccount], I think