Coder Social home page Coder Social logo

Comments (4)

adrien-may avatar adrien-may commented on August 23, 2024

Hi Kevin, I'm really happy this lib is useful to someone else than me. I have some plans to extend it to work outside of typeorm but I'm giving myself some time to think about it

You can achieve what you want with what I called LazyAttribute. You can apply a function which get as an argument the instance to be created. In your case, it means you could access your name property !
There is an example in the readme about LazyAttribute

from factory.

adrien-may avatar adrien-may commented on August 23, 2024

Unless there is a bug with the implementation, I'll close this issue

from factory.

kevin-mitchell avatar kevin-mitchell commented on August 23, 2024

Thanks so much for taking the time to make the tool.

I spent some time looking at some of the other options and like your approach. Clearly I should have spent some more time reading your documentation instead :).

I will take a look at the LazyAttribute, it sounds like what I want!

One other unrelated note (I can make an issue if you want for tracking?) - I think it might be useful to add more information about HOW the persistence works with TypeORM. You have

The adapter allows you to persist your data. If you want to save your data in a database via typeorm, you can use the TypeormAdapter. Default Adapter is ObjectAdapter and does not persist anything. You can create your own adapter to persist your data the way you want.

But it isn't clear to me from this documentation alone how this actually works, or what the intended work flow would be here. I will likely use this for seeding some basic data in lower dev / sandbox environments, or potentially for end-to-end testing, and I can always try to open a PR with more details if I get to it.

For now, thanks again, I'll close out this issue!

from factory.

adrien-may avatar adrien-may commented on August 23, 2024

If you need more information, you can have a look at typeorm
This project does not aim to document typeorm features.

But you can also use this lib without using typeorm !

It is quite common when using factories, seeding etc... to have data being persisted in a database, a file or whatever.
Factory uses a method called save to persist data. If no adapter is provided, this method does... almost nothing. Adapters, like the typeorm one, allow you to use typeorm features and save the data in your database. What is not written in my documentation is how typeorm should be setup, how you open a connection to your database etc... This should be covered on their documentation though.

If you need any kind of custom logic in your save method, you could write your own adapter to suit your needs.

from factory.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.