blob: 3b04ef5aa96b3f815983e59c262d6dfb44c71a10 [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Relationships &mdash; Apache Usergrid 1.0 documentation</title>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="top" title="Apache Usergrid 1.0 documentation" href="../index.html"/>
<script src="../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-nav-search">
<a href="../index.html" class="icon icon-home"> Apache Usergrid
</a>
<div class="version">
1.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Introduction</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../introduction/usergrid-features.html">Usergrid Features</a></li>
<li class="toctree-l1"><a class="reference internal" href="../introduction/data-model.html">Usergrid Data model</a></li>
<li class="toctree-l1"><a class="reference internal" href="../introduction/async-vs-sync.html">Async vs. sync calls</a></li>
</ul>
<p class="caption"><span class="caption-text">Getting Started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../getting-started/creating-a-new-application.html">Creating a new application</a></li>
<li class="toctree-l1"><a class="reference internal" href="../getting-started/creating-account.html">Creating an Usergrid Account</a></li>
<li class="toctree-l1"><a class="reference internal" href="../getting-started/using-a-sandbox-app.html">Using a Sandbox Application</a></li>
<li class="toctree-l1"><a class="reference internal" href="../getting-started/using-the-api.html">Using the API</a></li>
</ul>
<p class="caption"><span class="caption-text">Data Storage</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/data-store-dbms.html">The Usergrid Data Store</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/optimizing-access.html">Data Store Best Practices</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/collections.html">Collections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/entities.html">Entities</a></li>
</ul>
<p class="caption"><span class="caption-text">Data Queries</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/querying-your-data.html">Querying your data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/query-parameters.html">Query parameters &amp; clauses</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/operators-and-types.html">Query operators &amp; data types</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/advanced-query-usage.html">Advanced query usage</a></li>
</ul>
<p class="caption"><span class="caption-text">Entity Connections</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="connecting-entities.html">Connecting entities</a></li>
<li class="toctree-l1"><a class="reference internal" href="retrieving-entities.html">Retrieving connections</a></li>
<li class="toctree-l1"><a class="reference internal" href="disconnecting-entities.html">Disconnecting entities</a></li>
</ul>
<p class="caption"><span class="caption-text">Security &amp; Authentication</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/app-security.html">Security &amp; token authentication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/using-permissions.html">Using permissions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/authenticating-users-and-application-clients.html">Authenticating users &amp; app clients</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/user-authentication-types.html">Authentication levels</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/changing-token-time-live-ttl.html">Changing token expiration (time-to-live)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/authenticating-api-requests.html">Authenticating API requests</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/revoking-tokens-logout.html">Revoking tokens (logout)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/facebook-sign.html">Facebook sign in</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/securing-your-app.html">Security best practices</a></li>
</ul>
<p class="caption"><span class="caption-text">User Management &amp; Social Graph</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../user-management/user-management.html">User management &amp; social graph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/working-user-data.html">Working with User Data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/group.html">Working with group data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/activity.html">Activity</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/user-connections.html">Social Graph Connections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/user-connections.html#creating-other-connections">Creating other connections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/messagee-example.html">App Example - Messagee</a></li>
</ul>
<p class="caption"><span class="caption-text">Geo-location</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../geolocation/geolocation.html">Geolocating your Entities</a></li>
</ul>
<p class="caption"><span class="caption-text">Assets &amp; Files</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../asset-and-files/uploading-assets.html">Uploading assets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../asset-and-files/retrieving-assets.html">Retrieving assets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../asset-and-files/folders.html">Folders</a></li>
</ul>
<p class="caption"><span class="caption-text">Counters &amp; Events</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../counters-and-events/events-and-counters.html">Counters &amp; events</a></li>
<li class="toctree-l1"><a class="reference internal" href="../counters-and-events/creating-and-incrementing-counters.html">Creating &amp; incrementing counters</a></li>
<li class="toctree-l1"><a class="reference internal" href="../counters-and-events/creating-and-incrementing-counters.html#decrementing-resetting-counters">Decrementing/resetting counters</a></li>
<li class="toctree-l1"><a class="reference internal" href="../counters-and-events/creating-and-incrementing-counters.html#using-counters-hierarchically">Using counters hierarchically</a></li>
<li class="toctree-l1"><a class="reference internal" href="../counters-and-events/retrieving-counters.html">Retrieving counters</a></li>
</ul>
<p class="caption"><span class="caption-text">Organizations &amp; Applications</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/managing.html">Organization &amp; application management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/organization.html">Organization</a></li>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/application.html">Application</a></li>
</ul>
<p class="caption"><span class="caption-text">API Reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../rest-endpoints/api-docs.html">Methods</a></li>
<li class="toctree-l1"><a class="reference internal" href="../rest-endpoints/api-docs.html#models">Models</a></li>
</ul>
<p class="caption"><span class="caption-text">Client SDKs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../sdks/tbd.html">COMING SOON...</a></li>
</ul>
<p class="caption"><span class="caption-text">Installing the Stack</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../installation/ug1-deploy-to-tomcat.html">Usegrid 1: Deploying to Tomcat</a></li>
<li class="toctree-l1"><a class="reference internal" href="../installation/ug1-launcher-quick-start.html">Usegrid 1: Launcher Quick-start</a></li>
<li class="toctree-l1"><a class="reference internal" href="../installation/ug2-deploy-to-tomcat.html">Usergrid 2: Deploy to Tomcat</a></li>
</ul>
<p class="caption"><span class="caption-text">More about Usergrid</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../reference/presos-and-videos.html">Presentations &amp; Videos</a></li>
<li class="toctree-l1"><a class="reference internal" href="../reference/contribute-code.html">How to Contribute Code &amp; Docs</a></li>
</ul>
</div>
&nbsp;
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">Apache Usergrid</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html">Docs</a> &raquo;</li>
<li>Relationships</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/entity-connections/relationships.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="relationships">
<h1>Relationships<a class="headerlink" href="#relationships" title="Permalink to this headline"></a></h1>
<div class="section" id="creating-connections-between-entities">
<h2>Creating connections between entities<a class="headerlink" href="#creating-connections-between-entities" title="Permalink to this headline"></a></h2>
<p>One of the most useful features of Usergrid is the ability to create
connections between entities. A simple example of this is the
Twitter-like use of <em>following</em>, where one user forms a connection with
another by subscribing to any tweets they post. <a class="reference external" href="/messagee-example">Messagee
Example</a> walks you through an example of following
other users in our sample app, <em>Messagee</em>. Here is the basic format:</p>
<div class="highlight-python"><div class="highlight"><pre>POST https://api.usergrid.com/my-org/my-app/users/fred/following/users/barney
</pre></div>
</div>
<p>This API call results in two users, Fred and Barney, linked with a
connection where Fred is following Barney.</p>
<p>If you create a <em>following</em> connection between two users, Apache
Usergrid automatically creates a virtual connection called <em>followers</em>
that mirrors the <em>following</em> connection. In other words, if you create a
connection where Fred is following Barney, Apache Usergrid automatically
creates a virtual connection where Fred is a follower of Barney.</p>
<p>Note that there is no mirror connection established. Apache Usergrid
only creates a mirror connection when you create a <em>following</em>
connection. It does not create a mirror connection for other verbs such
as likes.</p>
<p>You can see all the users that Fred is following, in this case only
Barney, by making the following API call:</p>
<div class="highlight-python"><div class="highlight"><pre>GET https://api.usergrid.com/my-org/my-app/users/fred/following
</pre></div>
</div>
<p>You can see all of barney’s followers, in this case only Fred, by making
the following API call:</p>
<div class="highlight-python"><div class="highlight"><pre>GET https://api.usergrid.com/my-org/my-app/users/barney/followers
</pre></div>
</div>
<p>The <em>followers</em> connection is a virtual connection because you can’t use
it to link two entities. In other words, you can’t make fred a follower
of barney by using a <em>followers</em> connection. &nbsp;<strong>This is wrong:</strong></p>
<div class="highlight-python"><div class="highlight"><pre>POST https://api.usergrid.com/my-org/my-app/users/barney/followers/users/fred
</pre></div>
</div>
<p>To create a <em>following</em> connection with the users switched, so that
Barney is following Fred, do this:</p>
<div class="highlight-python"><div class="highlight"><pre>POST https://api.usergrid.com/my-org/my-app/users/barney/following/users/fred
</pre></div>
</div>
<p>You can now see Fred’s followers (only Barney) by making the following
call:</p>
<div class="highlight-python"><div class="highlight"><pre>GET https://api.usergrid.com/my-org/my-app/users/fred/followers
</pre></div>
</div>
</div>
<div class="section" id="creating-other-connections">
<h2>Creating other connections<a class="headerlink" href="#creating-other-connections" title="Permalink to this headline"></a></h2>
<p>You can extend this connection structure to create connections using any
&#8220;verb&#8221; that can link two entities. For example, you could use likes to
denote a connection between a user and his dog. First, create a dogs
collection:</p>
<div class="highlight-python"><div class="highlight"><pre>POST https://api.usergrid.com/my-org/my-app/dogs
</pre></div>
</div>
<p>Then populate this collection with a new dog named Dino:</p>
<div class="highlight-python"><div class="highlight"><pre>POST https://api.usergrid.com/my-org/my-app/dogs {&quot;name&quot; : &quot;dino&quot;}
</pre></div>
</div>
<p>Then create a likes connection between Fred and his dog Dino:</p>
<div class="highlight-python"><div class="highlight"><pre>POST https://api.usergrid.com/my-org/my-app/users/fred/likes/dogs/dino
</pre></div>
</div>
</div>
<div class="section" id="getting-connections">
<h2>Getting connections<a class="headerlink" href="#getting-connections" title="Permalink to this headline"></a></h2>
<div class="section" id="get-all-connections-for-an-entity">
<h3>Get all connections for an entity<a class="headerlink" href="#get-all-connections-for-an-entity" title="Permalink to this headline"></a></h3>
<p>To get a list that only contains the connections, do a GET on the
connections sub-property of the entity:</p>
<div class="highlight-python"><div class="highlight"><pre>GET https://api.usergrid.com/my-org/my-app/users/fred/connections
</pre></div>
</div>
</div>
<div class="section" id="get-information-on-a-specific-connection-type">
<h3>Get information on a specific connection type<a class="headerlink" href="#get-information-on-a-specific-connection-type" title="Permalink to this headline"></a></h3>
<p>To get a list of users who like Fred:</p>
<div class="highlight-python"><div class="highlight"><pre>GET https://api.usergrid.com/my-org/my-app/users/fred/connecting/likes
</pre></div>
</div>
<p>To get a list of all dogs that Fred likes:</p>
<div class="highlight-python"><div class="highlight"><pre>GET https://api.usergrid.com/my-org/my-app/users/fred/likes/dog
</pre></div>
</div>
</div>
</div>
<div class="section" id="deleting-a-connection">
<h2>Deleting a connection<a class="headerlink" href="#deleting-a-connection" title="Permalink to this headline"></a></h2>
<p>You can delete a connection in a way similar to creating one. Just
replace the POST method with the DELETE method. For example, you can
delete the connection between fred and barney with the following API
call:</p>
<div class="highlight-python"><div class="highlight"><pre>DELETE https://api.usergrid.com/my-org/my-app/users/fred/following/barney
</pre></div>
</div>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2013-2015, Apache Usergrid.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'1.0',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>