title: Graph database - how to reference Nodes from within Relationship
body: <p>I'm preparing a graph database (using neo4j) to handle the kind of social network scenario:</p>
  
  <ul>
  <li>Users can <strong>Post</strong> to their walls, sharing the Posts with either specific users</li>
  <li>Users can send <strong>Messages</strong> to others </li>
  <li>A <strong>Message</strong> can either be a text or "link" to the <strong>Post</strong></li>
  </ul>
  
  <p>So I came up with the following idea: </p>
  
  <p>Users and Posts are the Nodes of the graph. When the user <code>A</code> creates a post <code>P</code> sharing it with both <code>B</code> and <code>C</code>, the following relationships are created: <code>A-[:posted]-&gt;p</code> and <code>p-[:shared_with]-&gt;B</code> and <code>p-[:shared_with]-&gt;C</code>. The <code>Post</code> data (id, text, date) are stored as properties of the <code>:posted</code> relation. </p>
  
  <p>For messages it's similar: <code>A-[:messaged]-&gt;C</code> for example. </p>
  
  <p>Now, if I want to share the post in a message, I include the <code>post_id</code> in <code>:messaged</code> properties. It allows me to pull all the messages (together with the posts linked) with a single Cypher query: </p>
  
  <pre><code>match (a:User) match (b) where a.username = "C" match a-[m:messaged]-b 
  optional match (x:User)-[p:posted]-&gt;(post:Post)
  where post.id = m.post_id
  return distinct
  m.post_id,
    startnode(m).username as from, 
    endnode(m).username as to ,
    x.username as PostAuthor,
    case x when null then "Message" else "Pulled Post" end as Type,
    case x when null then m.text else post.text end as Text, 
    m.date
  order by m.date asc
  </code></pre>
  
  <p>It doesn't <strong>look</strong> right to me though - since on the graph there's no visual connection between the <code>Post</code> and the message. But, I can't set a relation between Node and Relation, right? How should I do it in order to have it designed properly? </p>