Skip to content

Commit 844e0a5

Browse files
committed
readme
1 parent d185910 commit 844e0a5

File tree

3 files changed

+17
-57
lines changed

3 files changed

+17
-57
lines changed

README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func main() {
114114
})
115115
}
116116
```
117-
117+
After this step we can start using ORM.
118118
### Fetching an entity from database
119119
GolobbyORM makes it trivial to fetch entity from database using its primary key.
120120
```go
@@ -175,6 +175,10 @@ func (p Post) ConfigureRelations(r *orm.RelationConfigurator) {
175175
}
176176
```
177177
As you can see we are defining a `Post` entity which has a `HasMany` relation with `Comment`. You can configure how GolobbyORM queries `HasMany` relation with `orm.HasManyConfig` object, by default it will infer all fields for you.
178+
now you can use this relationship anywhere in your code.
179+
```go
180+
comments, err := orm.HasMany[Comment](post)
181+
```
178182
#### HasOne
179183
```go
180184
type Post struct {}
@@ -184,6 +188,10 @@ func (p Post) ConfigureRelations(r *orm.RelationConfigurator) {
184188
}
185189
```
186190
As you can see we are defining a `Post` entity which has a `HasOne` relation with `HeaderPicture`. You can configure how GolobbyORM queries `HasOne` relation with `orm.HasOneConfig` object, by default it will infer all fields for you.
191+
now you can use this relationship anywhere in your code.
192+
```go
193+
picture, err := orm.HasOne[HeaderPicture](post)
194+
```
187195
#### BelongsTo
188196
```go
189197
type Comment struct {}
@@ -193,7 +201,10 @@ func (c Comment) ConfigureRelations(r *orm.RelationConfigurator) {
193201
}
194202
```
195203
As you can see we are defining a `Comment` entity which has a `BelongsTo` relation with `Post` that we saw earlier. You can configure how GolobbyORM queries `BelongsTo` relation with `orm.BelongsToConfig` object, by default it will infer all fields for you.
196-
204+
now you can use this relationship anywhere in your code.
205+
```go
206+
post, err := orm.BelongsTo[Post](comment)
207+
```
197208
#### BelongsToMany
198209
```go
199210
type Post struct {}
@@ -209,6 +220,10 @@ func(c Category) ConfigureRelations(r *orm.RelationConfigurator) {
209220

210221
```
211222
we are defining a `Post` entity and also a `Category` entity which have a many2many relationship, as you can see it's mandatory for us to configure IntermediateTable name which GolobbyORM cannot infer by itself now.
223+
now you can use this relationship anywhere in your code.
224+
```go
225+
categories, err := orm.BelongsToMany[Category](post)
226+
```
212227
#### Saving with relation
213228
You may need to save an entity which has some kind of relation with another entity, in that case you can use `Add` method.
214229
```go

qb.go

-5
This file was deleted.

qm.go

-50
This file was deleted.

0 commit comments

Comments
 (0)