<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>BeamFoundry Rays ORM on BeamFoundryi Rays Orm</title><link>https://rays.bfdy.dev/rays-orm/</link><description>Recent content in BeamFoundry Rays ORM on BeamFoundryi Rays Orm</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://rays.bfdy.dev/rays-orm/index.xml" rel="self" type="application/rss+xml"/><item><title>1. Introduction</title><link>https://rays.bfdy.dev/rays-orm/docs/1-introduction/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rays.bfdy.dev/rays-orm/docs/1-introduction/</guid><description>&lt;h1 id="introduction--architecture"&gt;Introduction &amp;amp; Architecture&lt;a class="anchor" href="#introduction--architecture"&gt;&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;In standard Go applications, managing database transactions across multiple service layers usually requires&#10;polluting your function signatures by passing a &lt;code&gt;tx *gorm.DB&lt;/code&gt; parameter down the entire call stack.&#10;Furthermore, writing basic CRUD operations for every model leads to massive code duplication.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Rays ORM solves both of these enterprise problems natively.&lt;/strong&gt;&lt;/p&gt;&#10;&lt;h2 id="-simplifying-with-dot-imports"&gt;🧹 Simplifying with Dot Imports&lt;a class="anchor" href="#-simplifying-with-dot-imports"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Just like the core Rays framework, it is highly recommended to use Go&amp;rsquo;s dot import feature for the ORM package&#10;(&lt;code&gt;import . &amp;quot;github.com/BeamFoundry/rays-orm&amp;quot;&lt;/code&gt;). This allows you to use types like &lt;code&gt;OrmRepository&lt;/code&gt;,&#10;&lt;code&gt;OrmQueryFunc&lt;/code&gt;, and &lt;code&gt;GormTxManager&lt;/code&gt; directly without package prefixes, keeping your domain code exceptionally clean and readable.&lt;/p&gt;</description></item><item><title>2. Quickstart &amp; Setup</title><link>https://rays.bfdy.dev/rays-orm/docs/2-quickstart/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rays.bfdy.dev/rays-orm/docs/2-quickstart/</guid><description>&lt;h1 id="quickstart--setup"&gt;Quickstart &amp;amp; Setup&lt;a class="anchor" href="#quickstart--setup"&gt;&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;To use Rays ORM, you must define a Configuration Beam that provides a raw &lt;code&gt;*gorm.DB&lt;/code&gt; instance,&#10;and optionally a Migrator service to initialize your schema.&lt;/p&gt;&#10;&lt;h2 id="1-defining-the-database-beam"&gt;1. Defining the Database Beam&lt;a class="anchor" href="#1-defining-the-database-beam"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Use a standard Rays &lt;code&gt;Configuration&lt;/code&gt; struct to open your database connection and provide it to the container.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;package&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;config&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; (&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;gorm.io/driver/sqlite&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;gorm.io/gorm&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; . &lt;span style="color:#e6db74"&gt;&amp;#34;github.com/BeamFoundry/rays/pkg/core&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; . &lt;span style="color:#e6db74"&gt;&amp;#34;github.com/BeamFoundry/rays/pkg/lang&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;type&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;DBConfig&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;struct&lt;/span&gt; {&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;Configuration&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Provides the raw *gorm.DB Beam to the container&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; (&lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;DBConfig&lt;/span&gt;) &lt;span style="color:#a6e22e"&gt;DB&lt;/span&gt;() (&lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;gorm&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;DB&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;Error&lt;/span&gt;) {&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;db&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;err&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;gorm&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Open&lt;/span&gt;(&lt;span style="color:#a6e22e"&gt;sqlite&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Open&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;file::memory:&amp;#34;&lt;/span&gt;), &lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;gorm&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Config&lt;/span&gt;{}); &lt;span style="color:#a6e22e"&gt;err&lt;/span&gt; &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;nil&lt;/span&gt; {&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;db&lt;/span&gt;, &lt;span style="color:#66d9ef"&gt;nil&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; } &lt;span style="color:#66d9ef"&gt;else&lt;/span&gt; {&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;nil&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;NewErrorFrom&lt;/span&gt;(&lt;span style="color:#a6e22e"&gt;err&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="2-auto-migrations"&gt;2. Auto-Migrations&lt;a class="anchor" href="#2-auto-migrations"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Because the database is a standard Beam, you can inject it into a &lt;code&gt;Service&lt;/code&gt; to handle auto-migrations during&#10;the &lt;code&gt;PostConstruct&lt;/code&gt; lifecycle phase. You can utilize the Rays &lt;code&gt;Try / RaiseErr&lt;/code&gt; pattern for clean error handling.&lt;/p&gt;</description></item><item><title>3. Auto-Generated Repositories</title><link>https://rays.bfdy.dev/rays-orm/docs/3-repositories/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rays.bfdy.dev/rays-orm/docs/3-repositories/</guid><description>&lt;h1 id="auto-generated-repositories"&gt;Auto-Generated Repositories&lt;a class="anchor" href="#auto-generated-repositories"&gt;&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;Rays ORM eliminates CRUD boilerplate by automatically implementing interface methods based on their function signatures.&lt;/p&gt;&#10;&lt;h2 id="1-the-base-repository"&gt;1. The Base Repository&lt;a class="anchor" href="#1-the-base-repository"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Rays provides &lt;code&gt;OrmRepository[T, ID]&lt;/code&gt;, which automatically provides implementations for the standard operations&#10;defined by the &lt;code&gt;OrmRepositoryInterface&lt;/code&gt;:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;Query(queries ...OrmQueryFunc) *gorm.DB&lt;/code&gt;&lt;/strong&gt;: Lets you execute queries on &lt;code&gt;&amp;lt;T&amp;gt;&lt;/code&gt;, calling gorm &lt;code&gt;Model() *gorm.DB&lt;/code&gt; first.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;FindById(id ID) Optional[*T]&lt;/code&gt;&lt;/strong&gt;: Lets you find an optional model pointer by its Id of type &lt;code&gt;&amp;lt;ID&amp;gt;&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;Delete(object *T) Error&lt;/code&gt;&lt;/strong&gt;: Lets you delete a model &lt;code&gt;&amp;lt;T&amp;gt;&lt;/code&gt; pointer, previously returned.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;DeleteById(id ID) Error&lt;/code&gt;&lt;/strong&gt;: Lets you delete a model using its id of type &lt;code&gt;&amp;lt;ID&amp;gt;&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;Save(object *T) (*T, Error)&lt;/code&gt;&lt;/strong&gt;: Saves a model &lt;code&gt;&amp;lt;T&amp;gt;&lt;/code&gt; pointer, returning the pointer and/or an &lt;code&gt;Error&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;SaveAll(object []*T) ([]*T, Error)&lt;/code&gt;&lt;/strong&gt;: Saves a slice of &lt;code&gt;&amp;lt;T&amp;gt;&lt;/code&gt; pointers, returning it and/or an &lt;code&gt;Error&lt;/code&gt;.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="2-the-query-builder-syntax"&gt;2. The Query Builder Syntax&lt;a class="anchor" href="#2-the-query-builder-syntax"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;To add custom queries, you define an unexported &lt;code&gt;func&lt;/code&gt; field on your struct. During container wiring, Rays ORM parses&#10;the name of the function field and &lt;strong&gt;automatically generates the GORM query code&lt;/strong&gt; to fulfill it.&lt;/p&gt;</description></item><item><title>4. ThreadLocal Transactions</title><link>https://rays.bfdy.dev/rays-orm/docs/4-transactions/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rays.bfdy.dev/rays-orm/docs/4-transactions/</guid><description>&lt;h1 id="threadlocal-transactions"&gt;ThreadLocal Transactions&lt;a class="anchor" href="#threadlocal-transactions"&gt;&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;A common pain point in Go is passing database transaction objects (&lt;code&gt;*gorm.DB&lt;/code&gt;) explicitly as arguments to&#10;every repository function.&lt;/p&gt;&#10;&lt;p&gt;Rays ORM utilizes &lt;code&gt;github.com/timandy/routine&lt;/code&gt; to establish &lt;strong&gt;ThreadLocal&lt;/strong&gt; state for your goroutines.&#10;When you start a transaction via the &lt;code&gt;GormTxManager&lt;/code&gt;, the transaction is stored in the local thread context.&lt;/p&gt;&#10;&lt;p&gt;When your auto-generated repositories execute queries, they transparently check the ThreadLocal context.&#10;If a transaction exists, they use it. If not, they use the global &lt;code&gt;*gorm.DB&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>5. Logging Integration</title><link>https://rays.bfdy.dev/rays-orm/docs/5-logging/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rays.bfdy.dev/rays-orm/docs/5-logging/</guid><description>&lt;h1 id="logging-integration"&gt;Logging Integration&lt;a class="anchor" href="#logging-integration"&gt;&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;The core Rays framework uses a centralized, &lt;code&gt;slog&lt;/code&gt;-based logging mechanism to ensure structured JSON output&#10;and trace contexts. GORM, however, has its own internal logging interface.&lt;/p&gt;&#10;&lt;p&gt;To maintain observability across your enterprise application, you should bridge GORM&amp;rsquo;s output directly into&#10;the Rays &lt;code&gt;Logging&lt;/code&gt; system. This prevents raw database queries from leaking into standard output as unformatted text.&lt;/p&gt;&#10;&lt;h2 id="bridging-gorm-to-slog"&gt;Bridging GORM to &lt;code&gt;slog&lt;/code&gt;&lt;a class="anchor" href="#bridging-gorm-to-slog"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;To unify your logging, we highly recommend using the &lt;code&gt;slog-gorm&lt;/code&gt; adapter package.&lt;/p&gt;</description></item><item><title>6. Testing &amp; Environments</title><link>https://rays.bfdy.dev/rays-orm/docs/6-testing-environments/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rays.bfdy.dev/rays-orm/docs/6-testing-environments/</guid><description>&lt;h1 id="testing--environments"&gt;Testing &amp;amp; Environments&lt;a class="anchor" href="#testing--environments"&gt;&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;Enterprise applications need to seamlessly switch databases based on the environment: a robust PostgreSQL instance for&#10;Production, and a fast, ephemeral SQLite instance for local testing.&lt;/p&gt;&#10;&lt;p&gt;By combining Rays ORM with the core framework&amp;rsquo;s &lt;code&gt;ConditionalOnProfile&lt;/code&gt; and &lt;code&gt;ConfigurationProperties&lt;/code&gt;, you can create a&#10;highly scalable environment strategy.&lt;/p&gt;&#10;&lt;h2 id="1-the-configuration-files"&gt;1. The Configuration Files&lt;a class="anchor" href="#1-the-configuration-files"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Define your connection strings in your standard YAML configuration files.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-yaml" data-lang="yaml"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# config/application.yaml (Default / Testing)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;app&lt;/span&gt;:&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;database&lt;/span&gt;:&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;dsn&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;file::memory:&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-yaml" data-lang="yaml"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# config/application-prod.yaml (Loaded only when &amp;#39;prod&amp;#39; profile is active)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;app&lt;/span&gt;:&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;database&lt;/span&gt;:&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;dsn&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;host=localhost user=gorm password=gorm dbname=gorm port=9920 sslmode=disable&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="2-the-dialector-strategy"&gt;2. The Dialector Strategy&lt;a class="anchor" href="#2-the-dialector-strategy"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Create an interface to abstract the GORM Dialector opening logic, and implement it for both SQLite and Postgres.&lt;/p&gt;</description></item><item><title>7. Advanced Querying</title><link>https://rays.bfdy.dev/rays-orm/docs/7-advanced-querying/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rays.bfdy.dev/rays-orm/docs/7-advanced-querying/</guid><description>&lt;h1 id="advanced-querying"&gt;Advanced Querying&lt;a class="anchor" href="#advanced-querying"&gt;&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;The auto-generated repository methods (&lt;code&gt;findBy...&lt;/code&gt;) are excellent for standard CRUD operations.&#10;However, enterprise applications frequently require eager loading (preloads), pagination, and&#10;complex joins.&lt;/p&gt;&#10;&lt;p&gt;Rays ORM handles this complexity using the &lt;code&gt;OrmQueryFunc&lt;/code&gt; escape hatch, keeping your repository&#10;interfaces clean and putting data hydration logic squarely in the hands of the business service layer.&lt;/p&gt;&#10;&lt;h2 id="1-relationships--preloading"&gt;1. Relationships &amp;amp; Preloading&lt;a class="anchor" href="#1-relationships--preloading"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Instead of embedding eager-loading logic into the method name string, Rays ORM provides helper&#10;functions (&lt;code&gt;WithPreload&lt;/code&gt; and &lt;code&gt;WithJoins&lt;/code&gt;) that return an &lt;code&gt;OrmQueryFunc&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>8. Hooks &amp; Soft Deletes</title><link>https://rays.bfdy.dev/rays-orm/docs/8-hooks-and-soft-deletes/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rays.bfdy.dev/rays-orm/docs/8-hooks-and-soft-deletes/</guid><description>&lt;h1 id="lifecycle-hooks--soft-deletes"&gt;Lifecycle Hooks &amp;amp; Soft Deletes&lt;a class="anchor" href="#lifecycle-hooks--soft-deletes"&gt;&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;Understanding how GORM interacts with the Rays IoC container is crucial for structuring your&#10;enterprise business logic securely.&lt;/p&gt;&#10;&lt;h2 id="1-model-hooks-vs-service-logic-the-ioc-boundary"&gt;1. Model Hooks vs. Service Logic (The IoC Boundary)&lt;a class="anchor" href="#1-model-hooks-vs-service-logic-the-ioc-boundary"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;GORM provides native model hooks (e.g., &lt;code&gt;BeforeCreate&lt;/code&gt;, &lt;code&gt;AfterSave&lt;/code&gt;). It is tempting to place all your&#10;pre-save logic in these hooks, but you must respect the &lt;strong&gt;IoC Boundary&lt;/strong&gt;.&lt;/p&gt;&#10;&lt;p&gt;Models (like &lt;code&gt;User{}&lt;/code&gt;) are instantiated by the database driver, not by the Rays IoC container.&#10;Therefore, &lt;strong&gt;you cannot use the &lt;code&gt;@:&amp;quot;Inject&amp;quot;&lt;/code&gt; tag inside a GORM model.&lt;/strong&gt;&lt;/p&gt;</description></item></channel></rss>