Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set model.id and handle change/remove events. #1

Merged

Conversation

thruflo
Copy link
Contributor

@thruflo thruflo commented Jul 31, 2012

Previously, the lib did not set the model.id attribute when populating a
collection from firebase. This meant that the models could not be identified
when child_changed or child_removed events came down the pipe.

This commit introduces a configurable idAttribute, which is populated with
the firebase reference name. Implementations then need to set the idAttribute
of their model class to use this as the source for the model.id value.

I've updated the readme accordingly but it might be worth providing a
FirebaseModel class that does this automatically, or generally considering
the best implementation.

In addition, I've patched up the update and delete event handlers to get the
existing model by id (rather than trying to collection.get(pushed_mode.val()).

Previously, the lib did not set the model.id attribute when populating a
collection from firebase.  This meant that the models could not be identified
when `child_changed` or `child_removed` events came down the pipe.

This commit introduces a configurable `idAttribute`, which is populated with
the firebase reference name.  Implementations then need to set the `idAttribute`
of their model class to use this as the source for the `model.id` value.

I've updated the readme accordingly but it might be worth providing a
`FirebaseModel` class that does this automatically, or generally considering
the best implementation.

In addition, I've patched up the update and delete event handlers to get the
existing model by id (rather than trying to `collection.get(pushed_mode.val())`.
@alexbain
Copy link
Owner

Looks good to me - thanks for taking the time to write this. Merging.

alexbain added a commit that referenced this pull request Jul 31, 2012
…11200a

Set `model.id` and handle change/remove events.
@alexbain alexbain merged commit 853aa22 into alexbain:master Jul 31, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants