This repository has been archived by the owner on Jul 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
active-record associations ? #7
Comments
It isn't "planned", but it is certainly on my wishlist. Do you know other implementations of relational mapping in JavaScript? I currently busy with other projects. If a pull request adds HAL support (http://stateless.co/hal_specification.html) |
I would like to suggest the following interface for associations: In your models. module('myApp', ['ActiveRecord']);
module('myApp').factory('Task', function (ActiveRecord, Comment) {
return ActiveRecord.extend({
$urlRoot: '/api/tasks',
$constructor: function Task(properties) {
this.$initialize.apply(this, arguments);
},
// An example method for loading associated records
$loadComments: function () {
// $hasMany will load all associated records by calling Comment.fetchAll({params: {task_id: this.id}})
// and return's array, with few methods:
// * $push - add new record to array
// * $build - build new record, and add it to array
this.$comments = this.$hasMany(Comment, {foreign_key : 'task_id'});
}
});
});
module('myApp').factory('Comment', function (ActiveRecord) {
return ActiveRecord.extend({
$urlRoot: '/api/comment',
$constructor: function Comment(properties) {
this.$initialize.apply(this, arguments)
}
});
}); In your controllers.
Do you like this DSL? |
xob
pushed a commit
to cognibox/angular-activerecord
that referenced
this issue
Apr 16, 2019
CBX-35 - Fix notEmpty validation
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
hi, any plans for support of active-record associations? thanks!
Chris
The text was updated successfully, but these errors were encountered: