Frieda
Frieda

Reputation: 163

Rails Neo4j Migration Argument Error

So I have these two classes

class Tweet 
  include Neo4j::ActiveNode
  property :content, type: String

  property :created_at, type: DateTime
  property :updated_at, type: DateTime
  has_one(:user, :tweeted).from(:User)
end

class User 
  include Neo4j::ActiveNode
  property :username, type: String
  property :name, type: String
  property :email, type: String, default: ''
  validates :email, :username, uniqueness: true
  property :encrypted_password
  has_many(:Tweet, :tweeted)
end

And everytime I run rails neo4j:migrate it gives error like this

ArgumentError: The 'type' option must be specified( even if it is nil) or origin/rel_class must be specified (Class#tweeted)

How to properly create relationship between nodes in neo4jrb?

Upvotes: 1

Views: 36

Answers (1)

alex kucksdorf
alex kucksdorf

Reputation: 2633

As the error message describes, you didn't explicitly define the type of your tweeted relation. Take a look at the official documentation for further details. However, the following should work:

class Tweet 
  include Neo4j::ActiveNode
  property :content, type: String
  property :created_at, type: DateTime
  property :updated_at, type: DateTime
  has_one :out, :author, type: :author, model_class: :User
end

class User 
  include Neo4j::ActiveNode
  property :username, type: String
  property :name, type: String
  property :email, type: String, default: ''
  validates :email, :username, uniqueness: true
  property :encrypted_password
  has_many :in, :tweets, origin: :author
end

Upvotes: 1

Related Questions