Comments (7)
Actually, when I wrote this I thought I could just have a CurrentUserModel and I made one, but then I realized that I can't do this because it's going to try and look for a current_user
table :\
from model.
We haven't implemented this, but subclassing models in an ORM is something you can do (although it's complicated: http://blog.thirst.co/post/14885390861/rails-single-table-inheritance).
It sounds like what you're really wanting is a way to specify what fields get returned in a serialization. This is essentially the "scenario-based serialization" we've talked about a lot. We already handle specific scenarios for validation, and it makes sense to do the same thing for serialization.
from model.
Right now I'm looking for a way to hide the property type
.
{
"createdAt": "2015-05-26T21:12:58.373Z",
"userName": "mdesales",
"content": "The document can be just like this...",
"id": "0907B712-FB7F-4D4A-8708-452C01B29F9C",
"type": "Document"
}
Is there a way to do that?
from model.
@marcellodesales I actually had to write some kinda crazy code which we call our create-response
component which turns model data into a response that I can actually send to clients. One of the things it does is removes the type
property (as well as others like password
). I clone the model object, loop through each property recursively through associations, turn to snake_case, and if it's on the blacklist I remove it.
It'd be nice if model did this sort of thing itself and created client ready responses, but I do realize that's probably out of the scope of the project. If you'd like @marcellodesales I can send you the custom component that's pretty specific to our app but maybe you can alter it to fit your needs. Hit me up at [email protected] and I'll send you the code.
from model.
Hi @OscarGodson
That would be awesome! StrongLoop's LoopBack does exactly that... We can set which properties should be hidden or not...
I will email you! It definitely would help... But hey, why don't we work to get a feature request to this project? I think this is a valid feature it should support...
thanks a lot for the message!
from model.
I recently contributed to a rails project a bit, and so I was exposed to their pattern of "Serializers". A serializer becomes a function that takes a payload of models and returns a JSON result, exists in app/serializers/yourModelName.js
, and is automatically applied when you call this.render()
from a same-titled controller.
This is a pretty clever pattern, and it might be a nice addition to Geddy as a whole.
from model.
@FlySwatter This is exactly what we're talking about with scenario-based serialization. Is this a part of Rails, or AR?
from model.
Related Issues (20)
- How do I save data to association models? HOT 5
- Null character in text body crashes PG adapter HOT 5
- Data from database different than model returns HOT 6
- Real number not always a good choice. HOT 3
- createdAt and updatedAt HOT 1
- New Eager Loading Bug! HOT 6
- PG Adapter Presently Only Fakes Streaming HOT 7
- TypeError: Cannot call method 'collection' of undefined. HOT 4
- Redis adapter HOT 1
- PG 9.3: ERROR column "foobar.created_at" must appear in the GROUP BY clause or be used in an aggregate function HOT 1
- some questions about update
- Complex query question HOT 1
- why finally sql's tablename have `s`or `es` HOT 1
- Can you only updateProperties per model? HOT 10
- Rest-adapter: Instance cache lifetime HOT 1
- How to write a custom adapter HOT 1
- cast json fields to string before applying queries
- about `save` method and model's id HOT 3
- Save Method issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from model.