Learning Center

Learning Center

Learn Menu

Weak Flag

Weak is a conceptual flag of design intent. Models have relationships, but sometimes they have a circular relationship. While OneGen doesn't mind that, the generated models might, or rather the programming language or database.

Imagine you're designing a Notes app. There are two models: User and Note. User can have many notes, so we add 1:m relationship to the User: notes: [Note]. Notes on the other hand always belong to a User, so we'd add a 1:1 relationship to the Note: user: User.

Understanding Strong and Weak

If you're not familiar with the concept of a strong/weak reference, we feel it'd be best to read about it for the programming language of your expertise. We'll do our best to explain the concept, but please keep in mind it won't correctly apply to all programming languages out there.

To simplify it, you could think of a strong reference being required while a weak reference is optional.

  • By using a strong reference you're saying: I need to use this reference, so you better keep it in the memory for as long as I need it.
  • By using a weak reference you're saying: I'd like to use this reference, but don't sweat it, if you need to clean up the memory, or if the referenced type is not active anymore, feel free to erase it. I'm not counting on it.

Analysing the issue

OneGen supports a variety of programming languages/technologies and plans to support a lot more. Even though some languages can deal with circular references on their own, we can't make a flat statement. OneGen cannot automatically flag one reference as weak because that may not align with your existing system requirements.

If your design contains circular relationships/references, only you can get a sense of the data flow and we recommend always flagging one end as weak. For engines where circular references don't pose an issue, the generated code should be the same.

We use cookies to track activity using Google Analytics & reCAPTCHA. It helps us understand what our visitors like about our product and how they interact with our website. For more information, check out our Privacy Policy.