Skip to content

Commit 3acbc27

Browse files
committed
readme
1 parent 9c4cb30 commit 3acbc27

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ _, affected, err := orm.Query[Post]().Where("id", 1).Delete()
165165
_, affected, err := orm.ExecRaw[Post](`DELETE FROM posts WHERE id=?`, 1)
166166
```
167167
### Relationships
168-
GolobbyORM makes it easy to have entities that have relationships with each other. As you have already seen in entity definition
169-
you have a `ConfigureRelations` method which let's you define relations of an `Entity`.
168+
GolobbyORM makes it easy to have entities that have relationships with each other. Configuring relations is using `ConfigureEntity` method as you will see.
170169
#### HasMany
171170
```go
172171
type Post struct {}
@@ -178,9 +177,15 @@ func (p Post) ConfigureEntity(e *orm.EntityConfigurator) {
178177
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.
179178
now you can use this relationship anywhere in your code.
180179
```go
181-
comments, err := orm.HasMany[Comment](post)
180+
comments, err := orm.HasMany[Comment](post).All()
181+
```
182+
`HasMany` and other relation functions in GolobbyORM return `QueryBuilder` and you can use them like other query builders and create even more
183+
complex queries for relationships. for example you can create a query for getting all comments of a post that are created today.
184+
```go
185+
todayComments, err := orm.HasMany[Comment](post).Where("created_at", "CURDATE()").All()
182186
```
183187
#### HasOne
188+
Configuring a `HasOne` relation is like `HasMany`.
184189
```go
185190
type Post struct {}
186191

@@ -193,6 +198,7 @@ now you can use this relationship anywhere in your code.
193198
```go
194199
picture, err := orm.HasOne[HeaderPicture](post)
195200
```
201+
`HasOne` also returns a query builder and you can create more complex queries for relations.
196202
#### BelongsTo
197203
```go
198204
type Comment struct {}

0 commit comments

Comments
 (0)