id
Uniquely identify an instance or raw instance data.
connection.id(instance)
Returns the idProp if it exists, otherwise the algebra's
id values, otherwise the id property.
Parameters
- instance
{Instance|Object}:The instance or raw
propsfor an instance.
Returns
{String|Number}:
A string or number uniquely representing instance.
Use
Many extensions, such as the can-connect/constructor/store/store, need
to have a unique identifier for an instance or instance data. The
connection.id method should return that.
Typically, an item's id is a simply propertly value on the object.
For example, todo data might look like:
{_id: 5, name: "do the dishes"}
In this case, algebra's id comparator should be set to
"_id" like:
var algebra = new set.Algebra({
set.comparators.id("_id")
});
connect([...],{algebra: algebra});
However,
some data sources have compound ids. For example, "Class Assignment"
connection might be represented by two properties, the studentId and the
classId. For this kind of setup, you can provide your own id function as
follows:
var classAssignmentConnection = connect(['data-url'],{
url: "/class_assignments",
id: function(classAssignment){
return classAssignment.studentId+"-"+classAssignment.classId;
}
});