ruby on rails - How to define these owner/member relationships in Neo4j.rb? -


i'm trying figure out how define these owner/member relationships in neo4j.rb active::node models.

  • users can create many teams (and become "owner" of teams)
  • users can fetch teams have created
  • teams have single owner (user) , many members (other users)
  • owners can add other users members team
  • users can fetch teams either owner or member of

so far have this, isn't working right , totally lost.

class user   include neo4j::activenode   has_many :out, :my_teams, model_class: 'team' end  class team   include neo4j::activenode   property :name, type: string   has_one :in, :owner, model_class: 'user' end  user = create(:user) team = build(:team) user.my_teams << team expect(team.owner).to eq user 

firstly should make sure you're using 5.0.0 of gems released yesterday (yay!)

secondly (and should error messages when upgrade), should specifying type option associations, this:

class user   include neo4j::activenode   has_many :out, :my_teams, type: :owns_team, model_class: 'team' end 

that tells activenode relationship types use creation , querying.

lastly, creation use class methods on model classes this:

user = user.create team = team.create  user.my_teams << team 

on picky personal note, i'd suggest association name of teams or owned_teams because creates methods use teams user object.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -