Using factory attrs in route handlers
See original GitHub issueWhen I am creating a new record, from a POST request, the record created does not contain all properties of the factory that is defined. For example.
I have a page for new user, the post request sends only the user password and username. However, the factory has a few additional properties:
- username
- password
- createdAt
- updatedAt
As I said, the request.requestBody only contains “username” and “password” and when I create a new record, the createdAt and updatedAt properties are not created
var body = { username: 'sam', password: '1234' }
var newUser = db.users.insert(body)
console.log(newUser) // { id: 123, username: 'sam', password: '1234' }
Issue Analytics
- State:
- Created 8 years ago
- Comments:16 (1 by maintainers)
Top Results From Across the Web
Using factory attrs in route handlers #231 - GitHub
When I am creating a new record, from a POST request, the record created does not contain all properties of the factory that...
Read more >Routing to controller actions in ASP.NET Core - Microsoft Learn
ASP.NET Core controllers use the Routing middleware to match the URLs of incoming requests and map them to actions. Route templates:.
Read more >attrs by Example - attrs 22.2.0 documentation
Attributes can have a converter function specified, which will be called with the attribute's passed-in value to get a new value to use....
Read more >How can I get ServerRequestInterface with attributes in Factory?
When initializing some services in the factory, I need to get data from the request attributes. How can i do this?
Read more >attrs - Release 22.2.0.dev0 Hynek Schlawack - Read the Docs
Since they take an attrs instance as their first argument, you can attach them to your classes with one line of code. Performance...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A constructor like function on the model would be super useful for setting default values such as created at. The model feels like a better place for this rather than injecting default values in at the route level, especially for apps using mirage shorthands and plain JSON API.
@samselikoff We would actually like to be able to have this type of functionality for POST-ing. Some our systems only take a single field and then populate the rest of the data from other sources on the server side. It would be convenient to use Factories and faker.js to be able to achieve a similar effect in our mocks/tests.