SingleRecordResource
A Resource oriented towards a single record: data is a single object, supporting retrieval by primary key, creation/updating (save), and deletion. It is suitable for "single record" scenarios such as details and forms. Unlike MultiRecordResource, the getData() method of SingleRecordResource returns a single object. You specify the primary key via setFilterByTk(id), and save() will automatically call create or update based on the isNewRecord state.
Inheritance: FlowResource → APIResource → BaseRecordResource → SingleRecordResource.
Creation: ctx.makeResource('SingleRecordResource') or ctx.initResource('SingleRecordResource'). You must call setResourceName('collectionName') before use. When performing operations by primary key, call setFilterByTk(id). In RunJS, ctx.api is injected by the runtime environment.
Use Scenarios
Data Format
getData()returns a single record object, which corresponds to thedatafield of thegetAPI response.getMeta()returns metadata (if available).
Resource Name and Primary Key
State
Request Parameters (Filter / Fields)
CRUD
Configuration and Events
Examples
Basic Retrieval and Update
Create New Record
Delete Record
Association Loading and Fields
Association Resources (e.g., users.profile)
Save Without Auto-Refresh
Listening to refresh / saved Events
Notes
- setResourceName is Required: You must call
setResourceName('collectionName')before use, otherwise the request URL cannot be constructed. - filterByTk and isNewRecord: If
setFilterByTkis not called,isNewRecordistrue, andrefresh()will not initiate a request;save()will execute acreateaction. - Association Resources: When the resource name is in
parent.childformat (e.g.,users.profile), you must callsetSourceId(parentPrimaryKey)first. - getData Returns an Object: The
datareturned by single-record APIs is a record object;getData()returns this object directly. It becomesnullafterdestroy().
Related
- ctx.resource - The resource instance in the current context
- ctx.initResource() - Initialize and bind to
ctx.resource - ctx.makeResource() - Create a new resource instance without binding
- APIResource - General API resource requested by URL
- MultiRecordResource - Oriented towards collections/lists, supporting CRUD and pagination

