Skip to content

Commit

Permalink
documented the fact that prefetch is not allowed on mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Jouhier authored and Bruno Jouhier committed Oct 18, 2010
1 parent b1ca96e commit de89d62
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -245,6 +245,9 @@ And you can also traverse the reverse relationship from a `Note` to its `annotat

Note that `annotated` is a polymorphic relationship as it may yield either a `Project`
or a `Task` (or any other entity which is `Annotatable').

Note: Prefetch is not allowed on a relationship that targets a mixin. In the example above
you cannot prefetch the `annotated` relationship when querying the `Note` entity.

Notes: this feature is very experimental at this stage. It needs more testing.
Support for "is a" relationships (classical inheritence) is also in the works.
Expand Down
1 change: 1 addition & 0 deletions lib/persistence.js
Expand Up @@ -1531,6 +1531,7 @@ persistence.get = function(arg1, arg2) {
/**
* Returns a new query collection which will prefetch a certain object relationship.
* Only works with 1:1 and N:1 relations.
* Relation must target an entity, not a mix-in.
* @param rel the relation name of the relation to prefetch
* @return the query collection prefetching `rel`
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/persistence.store.sql.js
Expand Up @@ -615,6 +615,8 @@ persistence.store.sql.config = function(persistence, dialect) {
for ( var i = 0; i < this._prefetchFields.length; i++) {
var prefetchField = this._prefetchFields[i];
var thisMeta = meta.hasOne[prefetchField].type.meta;
if (thisMeta.isMixin)
throw new Error("cannot prefetch a mixin");
var tableAlias = thisMeta.name + '_' + prefetchField + "_tbl";
selectFields = selectFields.concat(selectAll(thisMeta, tableAlias,
prefetchField + "_"));
Expand Down

0 comments on commit de89d62

Please sign in to comment.