[{"data":1,"prerenderedAt":3727},["ShallowReactive",2],{"navigation_docs_en":3,"-en-tauri-sqlite-orm-advanced-topics-working-with-relations":237,"-en-tauri-sqlite-orm-advanced-topics-working-with-relations-surround":3722},[4,15,69,122],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":14},"Getting Started with Docs","i-lucide-home","/en/getting-started","en/1.getting-started",[10],{"title":11,"path":12,"stem":13,"icon":6},"Introduction","/en/getting-started/introduction","en/1.getting-started/1.introduction",false,{"title":16,"path":17,"stem":18,"children":19,"page":14},"owo-ui Components","/en/owo-ui-components","en/2.owo-ui-components",[20,23],{"title":11,"path":21,"stem":22,"icon":6},"/en/owo-ui-components/introduction","en/2.owo-ui-components/2.introduction",{"title":24,"icon":25,"path":26,"stem":27,"children":28,"page":14},"Components","i-lucide-layout","/en/owo-ui-components/components","en/2.owo-ui-components/3.components",[29,33,37,41,45,49,53,57,61,65],{"title":30,"path":31,"stem":32},"Button","/en/owo-ui-components/components/button","en/2.owo-ui-components/3.components/button",{"title":34,"path":35,"stem":36},"Checkbox","/en/owo-ui-components/components/checkbox","en/2.owo-ui-components/3.components/checkbox",{"title":38,"path":39,"stem":40},"Collapsible Container","/en/owo-ui-components/components/collapsible-container","en/2.owo-ui-components/3.components/collapsible-container",{"title":42,"path":43,"stem":44},"Dropdown","/en/owo-ui-components/components/dropdown","en/2.owo-ui-components/3.components/dropdown",{"title":46,"path":47,"stem":48},"Flow Layout","/en/owo-ui-components/components/flow-layout","en/2.owo-ui-components/3.components/flow-layout",{"title":50,"path":51,"stem":52},"Grid Layout","/en/owo-ui-components/components/grid-layout","en/2.owo-ui-components/3.components/grid-layout",{"title":54,"path":55,"stem":56},"Label","/en/owo-ui-components/components/label","en/2.owo-ui-components/3.components/label",{"title":58,"path":59,"stem":60},"Scroll Container","/en/owo-ui-components/components/scroll-container","en/2.owo-ui-components/3.components/scroll-container",{"title":62,"path":63,"stem":64},"Slider","/en/owo-ui-components/components/slider","en/2.owo-ui-components/3.components/slider",{"title":66,"path":67,"stem":68},"Templates","/en/owo-ui-components/components/templates","en/2.owo-ui-components/3.components/templates",{"title":70,"path":71,"stem":72,"children":73,"page":14},"Nexus","/en/nexus","en/3.nexus",[74,77,82],{"title":11,"path":75,"stem":76,"icon":6},"/en/nexus/introduction","en/3.nexus/2.introduction",{"title":78,"path":79,"stem":80,"icon":81},"Deployment","/en/nexus/deployment","en/3.nexus/3.deployment","i-lucide-rocket",{"title":83,"path":84,"stem":85,"children":86,"page":14},"Endpoints","/en/nexus/endpoints","en/3.nexus/endpoints",[87,91,95,99,102,106,110,114,118],{"title":88,"path":89,"stem":90},"Authentication","/en/nexus/endpoints/authentication","en/3.nexus/endpoints/1.authentication",{"title":92,"path":93,"stem":94},"Rate Limiting","/en/nexus/endpoints/rate-limiting","en/3.nexus/endpoints/2.rate-limiting",{"title":96,"path":97,"stem":98},"Error Handling","/en/nexus/endpoints/error-handling","en/3.nexus/endpoints/3.error-handling",{"title":83,"path":100,"stem":101},"/en/nexus/endpoints/_dir","en/3.nexus/endpoints/_dir",{"title":103,"path":104,"stem":105},"Album","/en/nexus/endpoints/albums","en/3.nexus/endpoints/albums",{"title":107,"path":108,"stem":109},"Blog","/en/nexus/endpoints/blog","en/3.nexus/endpoints/blog",{"title":111,"path":112,"stem":113},"Comments","/en/nexus/endpoints/comments","en/3.nexus/endpoints/comments",{"title":115,"path":116,"stem":117},"File Management","/en/nexus/endpoints/file-management","en/3.nexus/endpoints/file-management",{"title":119,"path":120,"stem":121},"Photo Management","/en/nexus/endpoints/photos","en/3.nexus/endpoints/photos",{"title":123,"icon":124,"path":125,"stem":126,"children":127,"page":14},"Tauri SQLite ORM","i-lucide-database","/en/tauri-sqlite-orm","en/4.tauri-sqlite-orm",[128,132,137,141,162,187,232],{"title":11,"path":129,"stem":130,"icon":131},"/en/tauri-sqlite-orm/introduction","en/4.tauri-sqlite-orm/1.introduction","i-lucide-book-open",{"title":133,"path":134,"stem":135,"icon":136},"Installation & Setup","/en/tauri-sqlite-orm/installation-and-setup","en/4.tauri-sqlite-orm/2.installation-and-setup","i-lucide-download",{"title":138,"path":139,"stem":140,"icon":81},"Your First Schema & Query","/en/tauri-sqlite-orm/your-first-schema-and-query","en/4.tauri-sqlite-orm/3.your-first-schema-and-query",{"title":142,"path":143,"stem":144,"children":145,"page":14},"Core Concepts","/en/tauri-sqlite-orm/core-concepts","en/4.tauri-sqlite-orm/4.core-concepts",[146,150,154,158],{"title":147,"path":148,"stem":149},"Defining Schemas","/en/tauri-sqlite-orm/core-concepts/defining-schemas","en/4.tauri-sqlite-orm/4.core-concepts/1.defining-schemas",{"title":151,"path":152,"stem":153},"Column Types & Modifiers","/en/tauri-sqlite-orm/core-concepts/column-types-and-modifiers","en/4.tauri-sqlite-orm/4.core-concepts/2.column-types-and-modifiers",{"title":155,"path":156,"stem":157},"The ORM Instance","/en/tauri-sqlite-orm/core-concepts/the-orm-instance","en/4.tauri-sqlite-orm/4.core-concepts/3.the-orm-instance",{"title":159,"path":160,"stem":161},"Migrations","/en/tauri-sqlite-orm/core-concepts/migrations","en/4.tauri-sqlite-orm/4.core-concepts/4.migrations",{"title":163,"path":164,"stem":165,"children":166,"page":14},"Querying Data","/en/tauri-sqlite-orm/querying-data","en/4.tauri-sqlite-orm/5.querying-data",[167,171,175,179,183],{"title":168,"path":169,"stem":170},"Select","/en/tauri-sqlite-orm/querying-data/selecting-data","en/4.tauri-sqlite-orm/5.querying-data/1.selecting-data",{"title":172,"path":173,"stem":174},"Insert","/en/tauri-sqlite-orm/querying-data/inserting-data","en/4.tauri-sqlite-orm/5.querying-data/2.inserting-data",{"title":176,"path":177,"stem":178},"Update","/en/tauri-sqlite-orm/querying-data/updating-data","en/4.tauri-sqlite-orm/5.querying-data/3.updating-data",{"title":180,"path":181,"stem":182},"Delete","/en/tauri-sqlite-orm/querying-data/deleting-data","en/4.tauri-sqlite-orm/5.querying-data/4.deleting-data",{"title":184,"path":185,"stem":186},"Conditions & Operators","/en/tauri-sqlite-orm/querying-data/conditions-and-operators","en/4.tauri-sqlite-orm/5.querying-data/5.conditions-and-operators",{"title":188,"path":189,"stem":190,"children":191,"page":14},"Advanced Topics","/en/tauri-sqlite-orm/advanced-topics","en/4.tauri-sqlite-orm/6.advanced-topics",[192,196,200,204,208,212,216,220,224,228],{"title":193,"path":194,"stem":195},"Relations","/en/tauri-sqlite-orm/advanced-topics/working-with-relations","en/4.tauri-sqlite-orm/6.advanced-topics/1.working-with-relations",{"title":197,"path":198,"stem":199},"Error Handling & Safety","/en/tauri-sqlite-orm/advanced-topics/error-handling-and-safety","en/4.tauri-sqlite-orm/6.advanced-topics/10.error-handling-and-safety",{"title":201,"path":202,"stem":203},"Joins","/en/tauri-sqlite-orm/advanced-topics/joins","en/4.tauri-sqlite-orm/6.advanced-topics/2.joins",{"title":205,"path":206,"stem":207},"Transactions","/en/tauri-sqlite-orm/advanced-topics/transactions","en/4.tauri-sqlite-orm/6.advanced-topics/3.transactions",{"title":209,"path":210,"stem":211},"Common Table Expressions","/en/tauri-sqlite-orm/advanced-topics/common-table-expressions","en/4.tauri-sqlite-orm/6.advanced-topics/4.common-table-expressions",{"title":213,"path":214,"stem":215},"Raw SQL","/en/tauri-sqlite-orm/advanced-topics/raw-sql","en/4.tauri-sqlite-orm/6.advanced-topics/5.raw-sql",{"title":217,"path":218,"stem":219},"Type Safety & Inference","/en/tauri-sqlite-orm/advanced-topics/type-safety-and-inference","en/4.tauri-sqlite-orm/6.advanced-topics/6.type-safety-and-inference",{"title":221,"path":222,"stem":223},"Schema Management","/en/tauri-sqlite-orm/advanced-topics/manual-schema-management","en/4.tauri-sqlite-orm/6.advanced-topics/7.manual-schema-management",{"title":225,"path":226,"stem":227},"Query Debugging","/en/tauri-sqlite-orm/advanced-topics/query-debugging","en/4.tauri-sqlite-orm/6.advanced-topics/8.query-debugging",{"title":229,"path":230,"stem":231},"Subqueries & Aggregates","/en/tauri-sqlite-orm/advanced-topics/subqueries-and-aggregates","en/4.tauri-sqlite-orm/6.advanced-topics/9.subqueries-and-aggregates",{"title":233,"path":234,"stem":235,"icon":236},"API Reference","/en/tauri-sqlite-orm/api-reference","en/4.tauri-sqlite-orm/7.api-reference","i-lucide-book",{"id":238,"title":193,"body":239,"description":3716,"extension":3717,"links":3718,"meta":3719,"navigation":425,"path":194,"seo":3720,"stem":195,"__hash__":3721},"docs_en/en/4.tauri-sqlite-orm/6.advanced-topics/1.working-with-relations.md",{"type":240,"value":241,"toc":3696},"minimark",[242,246,249,254,266,277,319,338,343,352,963,970,981,988,991,1154,1160,1163,1312,1322,1326,1333,1351,1355,2173,2177,2185,2339,2357,2361,2364,2576,2580,2593,3105,3110,3161,3168,3447,3453,3457,3466,3634,3641,3645,3692],[243,244,245],"p",{},"Relations are a powerful, declarative feature that lets you query data from multiple tables and receive it as a clean, nested JSON object. This is the ORM's high-level, \"batteries-included\" approach to handling joins, abstracting away the underlying SQL complexity.",[243,247,248],{},"Instead of flat rows, you get results that mirror your data's structure, like a user object containing an array of their posts.",[250,251,253],"h2",{"id":252},"_1-defining-relations","1. Defining Relations",[243,255,256,257,261,262,265],{},"To use this feature, you must first define the relationships between your tables using the ",[258,259,260],"code",{},"relations"," helper. This should be done in your ",[258,263,264],{},"schema.ts"," file, alongside your table definitions.",[243,267,268,269,272,273,276],{},"There are two types of relations you can define: ",[258,270,271],{},"one"," and ",[258,274,275],{},"many",".",[278,279,280,305],"ul",{},[281,282,283,289,290,293,294,297,298,272,301,304],"li",{},[284,285,286],"strong",{},[258,287,288],{},"one(foreignTable, config)",": Defines a ",[284,291,292],{},"many-to-one"," or ",[284,295,296],{},"one-to-one"," relationship. It signifies that the current table \"belongs to\" one record from the foreign table. You must specify which local and foreign columns connect the tables using ",[258,299,300],{},"fields",[258,302,303],{},"references"," (column references).",[281,306,307,289,312,315,316,318],{},[284,308,309],{},[258,310,311],{},"many(foreignTable)",[284,313,314],{},"one-to-many"," relationship. It signifies that the current table can be associated with many records from the foreign table. This is a \"back-reference\" and is inferred from a ",[258,317,271],{}," relation defined on the other table.",[243,320,321,322,325,326,272,328,330,331,334,335,276],{},"For ",[284,323,324],{},"many-to-many"," relationships, use a junction table with ",[258,327,271],{},[258,329,275],{}," relations, or use the v2 ",[258,332,333],{},"defineRelations"," API with ",[258,336,337],{},"through()",[339,340,342],"h3",{"id":341},"example-users-and-posts","Example: Users and Posts",[243,344,345,346,272,349,276],{},"Let's expand our schema to include relations between ",[258,347,348],{},"users",[258,350,351],{},"posts",[353,354,359],"pre",{"className":355,"code":356,"language":357,"meta":358,"style":358},"language-typescript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","// src/lib/db/schema.ts\nimport { sqliteTable, text, integer, relations } from '@type32/tauri-sqlite-orm';\n\n// ---- Tables ----\nexport const users = sqliteTable('users', {\n  id: integer('id').primaryKey().autoincrement(),\n  fullName: text('full_name').notNull(),\n});\n\nexport const posts = sqliteTable('posts', {\n  id: integer('id').primaryKey().autoincrement(),\n  title: text('title').notNull(),\n  authorId: integer('author_id').notNull().references(() => users._.columns.id),\n});\n\n\n// ---- Relations ----\n\n// Define relations for the 'posts' table\nexport const postsRelations = relations(posts, ({ one }) => ({\n  // A post has ONE author.\n  // The relation is named 'author'.\n  // Use column references: fields = local FK, references = foreign PK\n  author: one(users, {\n    fields: [posts._.columns.authorId],\n    references: [users._.columns.id],\n  }),\n}));\n\n// Define relations for the 'users' table\nexport const usersRelations = relations(users, ({ many }) => ({\n  // A user can have MANY posts.\n  // The relation is named 'posts'.\n  // The ORM will automatically find the corresponding 'one' relation on the 'posts' table.\n  posts: many(posts),\n}));\n","typescript","",[258,360,361,370,420,427,433,466,508,538,548,553,579,612,641,699,708,713,718,724,729,735,772,778,784,790,807,833,859,869,879,884,890,921,927,933,939,954],{"__ignoreMap":358},[362,363,366],"span",{"class":364,"line":365},"line",1,[362,367,369],{"class":368},"sHwdD","// src/lib/db/schema.ts\n",[362,371,373,377,381,385,388,391,393,396,398,401,404,407,410,414,417],{"class":364,"line":372},2,[362,374,376],{"class":375},"s7zQu","import",[362,378,380],{"class":379},"sMK4o"," {",[362,382,384],{"class":383},"sTEyZ"," sqliteTable",[362,386,387],{"class":379},",",[362,389,390],{"class":383}," text",[362,392,387],{"class":379},[362,394,395],{"class":383}," integer",[362,397,387],{"class":379},[362,399,400],{"class":383}," relations",[362,402,403],{"class":379}," }",[362,405,406],{"class":375}," from",[362,408,409],{"class":379}," '",[362,411,413],{"class":412},"sfazB","@type32/tauri-sqlite-orm",[362,415,416],{"class":379},"'",[362,418,419],{"class":379},";\n",[362,421,423],{"class":364,"line":422},3,[362,424,426],{"emptyLinePlaceholder":425},true,"\n",[362,428,430],{"class":364,"line":429},4,[362,431,432],{"class":368},"// ---- Tables ----\n",[362,434,436,439,443,446,449,452,455,457,459,461,463],{"class":364,"line":435},5,[362,437,438],{"class":375},"export",[362,440,442],{"class":441},"spNyl"," const",[362,444,445],{"class":383}," users ",[362,447,448],{"class":379},"=",[362,450,384],{"class":451},"s2Zo4",[362,453,454],{"class":383},"(",[362,456,416],{"class":379},[362,458,348],{"class":412},[362,460,416],{"class":379},[362,462,387],{"class":379},[362,464,465],{"class":379}," {\n",[362,467,469,473,476,478,480,482,485,487,490,492,495,498,500,503,505],{"class":364,"line":468},6,[362,470,472],{"class":471},"swJcz","  id",[362,474,475],{"class":379},":",[362,477,395],{"class":451},[362,479,454],{"class":383},[362,481,416],{"class":379},[362,483,484],{"class":412},"id",[362,486,416],{"class":379},[362,488,489],{"class":383},")",[362,491,276],{"class":379},[362,493,494],{"class":451},"primaryKey",[362,496,497],{"class":383},"()",[362,499,276],{"class":379},[362,501,502],{"class":451},"autoincrement",[362,504,497],{"class":383},[362,506,507],{"class":379},",\n",[362,509,511,514,516,518,520,522,525,527,529,531,534,536],{"class":364,"line":510},7,[362,512,513],{"class":471},"  fullName",[362,515,475],{"class":379},[362,517,390],{"class":451},[362,519,454],{"class":383},[362,521,416],{"class":379},[362,523,524],{"class":412},"full_name",[362,526,416],{"class":379},[362,528,489],{"class":383},[362,530,276],{"class":379},[362,532,533],{"class":451},"notNull",[362,535,497],{"class":383},[362,537,507],{"class":379},[362,539,541,544,546],{"class":364,"line":540},8,[362,542,543],{"class":379},"}",[362,545,489],{"class":383},[362,547,419],{"class":379},[362,549,551],{"class":364,"line":550},9,[362,552,426],{"emptyLinePlaceholder":425},[362,554,556,558,560,563,565,567,569,571,573,575,577],{"class":364,"line":555},10,[362,557,438],{"class":375},[362,559,442],{"class":441},[362,561,562],{"class":383}," posts ",[362,564,448],{"class":379},[362,566,384],{"class":451},[362,568,454],{"class":383},[362,570,416],{"class":379},[362,572,351],{"class":412},[362,574,416],{"class":379},[362,576,387],{"class":379},[362,578,465],{"class":379},[362,580,582,584,586,588,590,592,594,596,598,600,602,604,606,608,610],{"class":364,"line":581},11,[362,583,472],{"class":471},[362,585,475],{"class":379},[362,587,395],{"class":451},[362,589,454],{"class":383},[362,591,416],{"class":379},[362,593,484],{"class":412},[362,595,416],{"class":379},[362,597,489],{"class":383},[362,599,276],{"class":379},[362,601,494],{"class":451},[362,603,497],{"class":383},[362,605,276],{"class":379},[362,607,502],{"class":451},[362,609,497],{"class":383},[362,611,507],{"class":379},[362,613,615,618,620,622,624,626,629,631,633,635,637,639],{"class":364,"line":614},12,[362,616,617],{"class":471},"  title",[362,619,475],{"class":379},[362,621,390],{"class":451},[362,623,454],{"class":383},[362,625,416],{"class":379},[362,627,628],{"class":412},"title",[362,630,416],{"class":379},[362,632,489],{"class":383},[362,634,276],{"class":379},[362,636,533],{"class":451},[362,638,497],{"class":383},[362,640,507],{"class":379},[362,642,644,647,649,651,653,655,658,660,662,664,666,668,670,672,674,676,679,682,684,687,689,692,694,697],{"class":364,"line":643},13,[362,645,646],{"class":471},"  authorId",[362,648,475],{"class":379},[362,650,395],{"class":451},[362,652,454],{"class":383},[362,654,416],{"class":379},[362,656,657],{"class":412},"author_id",[362,659,416],{"class":379},[362,661,489],{"class":383},[362,663,276],{"class":379},[362,665,533],{"class":451},[362,667,497],{"class":383},[362,669,276],{"class":379},[362,671,303],{"class":451},[362,673,454],{"class":383},[362,675,497],{"class":379},[362,677,678],{"class":441}," =>",[362,680,681],{"class":383}," users",[362,683,276],{"class":379},[362,685,686],{"class":383},"_",[362,688,276],{"class":379},[362,690,691],{"class":383},"columns",[362,693,276],{"class":379},[362,695,696],{"class":383},"id)",[362,698,507],{"class":379},[362,700,702,704,706],{"class":364,"line":701},14,[362,703,543],{"class":379},[362,705,489],{"class":383},[362,707,419],{"class":379},[362,709,711],{"class":364,"line":710},15,[362,712,426],{"emptyLinePlaceholder":425},[362,714,716],{"class":364,"line":715},16,[362,717,426],{"emptyLinePlaceholder":425},[362,719,721],{"class":364,"line":720},17,[362,722,723],{"class":368},"// ---- Relations ----\n",[362,725,727],{"class":364,"line":726},18,[362,728,426],{"emptyLinePlaceholder":425},[362,730,732],{"class":364,"line":731},19,[362,733,734],{"class":368},"// Define relations for the 'posts' table\n",[362,736,738,740,742,745,747,749,752,754,757,761,764,766,769],{"class":364,"line":737},20,[362,739,438],{"class":375},[362,741,442],{"class":441},[362,743,744],{"class":383}," postsRelations ",[362,746,448],{"class":379},[362,748,400],{"class":451},[362,750,751],{"class":383},"(posts",[362,753,387],{"class":379},[362,755,756],{"class":379}," ({",[362,758,760],{"class":759},"sHdIc"," one",[362,762,763],{"class":379}," })",[362,765,678],{"class":441},[362,767,768],{"class":383}," (",[362,770,771],{"class":379},"{\n",[362,773,775],{"class":364,"line":774},21,[362,776,777],{"class":368},"  // A post has ONE author.\n",[362,779,781],{"class":364,"line":780},22,[362,782,783],{"class":368},"  // The relation is named 'author'.\n",[362,785,787],{"class":364,"line":786},23,[362,788,789],{"class":368},"  // Use column references: fields = local FK, references = foreign PK\n",[362,791,793,796,798,800,803,805],{"class":364,"line":792},24,[362,794,795],{"class":471},"  author",[362,797,475],{"class":379},[362,799,760],{"class":451},[362,801,802],{"class":383},"(users",[362,804,387],{"class":379},[362,806,465],{"class":379},[362,808,810,813,815,818,820,822,824,826,828,831],{"class":364,"line":809},25,[362,811,812],{"class":471},"    fields",[362,814,475],{"class":379},[362,816,817],{"class":383}," [posts",[362,819,276],{"class":379},[362,821,686],{"class":383},[362,823,276],{"class":379},[362,825,691],{"class":383},[362,827,276],{"class":379},[362,829,830],{"class":383},"authorId]",[362,832,507],{"class":379},[362,834,836,839,841,844,846,848,850,852,854,857],{"class":364,"line":835},26,[362,837,838],{"class":471},"    references",[362,840,475],{"class":379},[362,842,843],{"class":383}," [users",[362,845,276],{"class":379},[362,847,686],{"class":383},[362,849,276],{"class":379},[362,851,691],{"class":383},[362,853,276],{"class":379},[362,855,856],{"class":383},"id]",[362,858,507],{"class":379},[362,860,862,865,867],{"class":364,"line":861},27,[362,863,864],{"class":379},"  }",[362,866,489],{"class":383},[362,868,507],{"class":379},[362,870,872,874,877],{"class":364,"line":871},28,[362,873,543],{"class":379},[362,875,876],{"class":383},"))",[362,878,419],{"class":379},[362,880,882],{"class":364,"line":881},29,[362,883,426],{"emptyLinePlaceholder":425},[362,885,887],{"class":364,"line":886},30,[362,888,889],{"class":368},"// Define relations for the 'users' table\n",[362,891,893,895,897,900,902,904,906,908,910,913,915,917,919],{"class":364,"line":892},31,[362,894,438],{"class":375},[362,896,442],{"class":441},[362,898,899],{"class":383}," usersRelations ",[362,901,448],{"class":379},[362,903,400],{"class":451},[362,905,802],{"class":383},[362,907,387],{"class":379},[362,909,756],{"class":379},[362,911,912],{"class":759}," many",[362,914,763],{"class":379},[362,916,678],{"class":441},[362,918,768],{"class":383},[362,920,771],{"class":379},[362,922,924],{"class":364,"line":923},32,[362,925,926],{"class":368},"  // A user can have MANY posts.\n",[362,928,930],{"class":364,"line":929},33,[362,931,932],{"class":368},"  // The relation is named 'posts'.\n",[362,934,936],{"class":364,"line":935},34,[362,937,938],{"class":368},"  // The ORM will automatically find the corresponding 'one' relation on the 'posts' table.\n",[362,940,942,945,947,949,952],{"class":364,"line":941},35,[362,943,944],{"class":471},"  posts",[362,946,475],{"class":379},[362,948,912],{"class":451},[362,950,951],{"class":383},"(posts)",[362,953,507],{"class":379},[362,955,957,959,961],{"class":364,"line":956},36,[362,958,543],{"class":379},[362,960,876],{"class":383},[362,962,419],{"class":379},[250,964,966,967],{"id":965},"_2-querying-with-include","2. Querying with ",[258,968,969],{},"include",[243,971,972,973,976,977,980],{},"Once relations are defined, you can fetch them using the ",[258,974,975],{},".include()"," method on a ",[258,978,979],{},"select"," query. You pass an object specifying which relations to load.",[339,982,984,985,987],{"id":983},"one-to-many-many-example","One-to-Many (",[258,986,275],{},") Example",[243,989,990],{},"Let's fetch a user and all of their posts.",[353,992,996],{"className":993,"code":994,"language":995,"meta":358,"style":358},"language-ts shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","const userWithPosts = await db.select(users)\n  .where(eq(users._.columns.id, 1))\n  .include({ posts: true }) // Request the 'posts' relation\n  .get();\n\n/*\nResult Shape:\n{\n  id: 1,\n  fullName: 'Jane Doe',\n  posts: [\n    { id: 101, title: 'My First Post', authorId: 1 },\n    { id: 102, title: 'Another Post', authorId: 1 }\n  ]\n}\n*/\n","ts",[258,997,998,1021,1057,1085,1096,1100,1105,1110,1114,1119,1124,1129,1134,1139,1144,1149],{"__ignoreMap":358},[362,999,1000,1003,1006,1008,1011,1014,1016,1018],{"class":364,"line":365},[362,1001,1002],{"class":441},"const",[362,1004,1005],{"class":383}," userWithPosts ",[362,1007,448],{"class":379},[362,1009,1010],{"class":375}," await",[362,1012,1013],{"class":383}," db",[362,1015,276],{"class":379},[362,1017,979],{"class":451},[362,1019,1020],{"class":383},"(users)\n",[362,1022,1023,1026,1029,1031,1034,1036,1038,1040,1042,1044,1046,1048,1050,1054],{"class":364,"line":372},[362,1024,1025],{"class":379},"  .",[362,1027,1028],{"class":451},"where",[362,1030,454],{"class":383},[362,1032,1033],{"class":451},"eq",[362,1035,802],{"class":383},[362,1037,276],{"class":379},[362,1039,686],{"class":383},[362,1041,276],{"class":379},[362,1043,691],{"class":383},[362,1045,276],{"class":379},[362,1047,484],{"class":383},[362,1049,387],{"class":379},[362,1051,1053],{"class":1052},"sbssI"," 1",[362,1055,1056],{"class":383},"))\n",[362,1058,1059,1061,1063,1065,1068,1071,1073,1077,1079,1082],{"class":364,"line":422},[362,1060,1025],{"class":379},[362,1062,969],{"class":451},[362,1064,454],{"class":383},[362,1066,1067],{"class":379},"{",[362,1069,1070],{"class":471}," posts",[362,1072,475],{"class":379},[362,1074,1076],{"class":1075},"sfNiH"," true",[362,1078,403],{"class":379},[362,1080,1081],{"class":383},") ",[362,1083,1084],{"class":368},"// Request the 'posts' relation\n",[362,1086,1087,1089,1092,1094],{"class":364,"line":429},[362,1088,1025],{"class":379},[362,1090,1091],{"class":451},"get",[362,1093,497],{"class":383},[362,1095,419],{"class":379},[362,1097,1098],{"class":364,"line":435},[362,1099,426],{"emptyLinePlaceholder":425},[362,1101,1102],{"class":364,"line":468},[362,1103,1104],{"class":368},"/*\n",[362,1106,1107],{"class":364,"line":510},[362,1108,1109],{"class":368},"Result Shape:\n",[362,1111,1112],{"class":364,"line":540},[362,1113,771],{"class":368},[362,1115,1116],{"class":364,"line":550},[362,1117,1118],{"class":368},"  id: 1,\n",[362,1120,1121],{"class":364,"line":555},[362,1122,1123],{"class":368},"  fullName: 'Jane Doe',\n",[362,1125,1126],{"class":364,"line":581},[362,1127,1128],{"class":368},"  posts: [\n",[362,1130,1131],{"class":364,"line":614},[362,1132,1133],{"class":368},"    { id: 101, title: 'My First Post', authorId: 1 },\n",[362,1135,1136],{"class":364,"line":643},[362,1137,1138],{"class":368},"    { id: 102, title: 'Another Post', authorId: 1 }\n",[362,1140,1141],{"class":364,"line":701},[362,1142,1143],{"class":368},"  ]\n",[362,1145,1146],{"class":364,"line":710},[362,1147,1148],{"class":368},"}\n",[362,1150,1151],{"class":364,"line":715},[362,1152,1153],{"class":368},"*/\n",[339,1155,1157,1158,987],{"id":1156},"many-to-one-one-example","Many-to-One (",[258,1159,271],{},[243,1161,1162],{},"Now let's fetch a post and include its author.",[353,1164,1166],{"className":993,"code":1165,"language":995,"meta":358,"style":358},"const postWithAuthor = await db.select(posts)\n  .where(eq(posts._.columns.id, 101))\n  .include({ author: true }) // Request the 'author' relation\n  .get();\n\n/*\nResult Shape:\n{\n  id: 101,\n  title: 'My First Post',\n  authorId: 1,\n  author: {\n    id: 1,\n    fullName: 'Jane Doe'\n  }\n}\n*/\n",[258,1167,1168,1188,1219,1243,1253,1257,1261,1265,1269,1274,1279,1284,1289,1294,1299,1304,1308],{"__ignoreMap":358},[362,1169,1170,1172,1175,1177,1179,1181,1183,1185],{"class":364,"line":365},[362,1171,1002],{"class":441},[362,1173,1174],{"class":383}," postWithAuthor ",[362,1176,448],{"class":379},[362,1178,1010],{"class":375},[362,1180,1013],{"class":383},[362,1182,276],{"class":379},[362,1184,979],{"class":451},[362,1186,1187],{"class":383},"(posts)\n",[362,1189,1190,1192,1194,1196,1198,1200,1202,1204,1206,1208,1210,1212,1214,1217],{"class":364,"line":372},[362,1191,1025],{"class":379},[362,1193,1028],{"class":451},[362,1195,454],{"class":383},[362,1197,1033],{"class":451},[362,1199,751],{"class":383},[362,1201,276],{"class":379},[362,1203,686],{"class":383},[362,1205,276],{"class":379},[362,1207,691],{"class":383},[362,1209,276],{"class":379},[362,1211,484],{"class":383},[362,1213,387],{"class":379},[362,1215,1216],{"class":1052}," 101",[362,1218,1056],{"class":383},[362,1220,1221,1223,1225,1227,1229,1232,1234,1236,1238,1240],{"class":364,"line":422},[362,1222,1025],{"class":379},[362,1224,969],{"class":451},[362,1226,454],{"class":383},[362,1228,1067],{"class":379},[362,1230,1231],{"class":471}," author",[362,1233,475],{"class":379},[362,1235,1076],{"class":1075},[362,1237,403],{"class":379},[362,1239,1081],{"class":383},[362,1241,1242],{"class":368},"// Request the 'author' relation\n",[362,1244,1245,1247,1249,1251],{"class":364,"line":429},[362,1246,1025],{"class":379},[362,1248,1091],{"class":451},[362,1250,497],{"class":383},[362,1252,419],{"class":379},[362,1254,1255],{"class":364,"line":435},[362,1256,426],{"emptyLinePlaceholder":425},[362,1258,1259],{"class":364,"line":468},[362,1260,1104],{"class":368},[362,1262,1263],{"class":364,"line":510},[362,1264,1109],{"class":368},[362,1266,1267],{"class":364,"line":540},[362,1268,771],{"class":368},[362,1270,1271],{"class":364,"line":550},[362,1272,1273],{"class":368},"  id: 101,\n",[362,1275,1276],{"class":364,"line":555},[362,1277,1278],{"class":368},"  title: 'My First Post',\n",[362,1280,1281],{"class":364,"line":581},[362,1282,1283],{"class":368},"  authorId: 1,\n",[362,1285,1286],{"class":364,"line":614},[362,1287,1288],{"class":368},"  author: {\n",[362,1290,1291],{"class":364,"line":643},[362,1292,1293],{"class":368},"    id: 1,\n",[362,1295,1296],{"class":364,"line":701},[362,1297,1298],{"class":368},"    fullName: 'Jane Doe'\n",[362,1300,1301],{"class":364,"line":710},[362,1302,1303],{"class":368},"  }\n",[362,1305,1306],{"class":364,"line":715},[362,1307,1148],{"class":368},[362,1309,1310],{"class":364,"line":720},[362,1311,1153],{"class":368},[243,1313,1314,1315,1317,1318,1321],{},"Under the hood, ",[258,1316,975],{}," generates the necessary ",[258,1319,1320],{},"LEFT JOIN"," statements and then processes the flat results into these convenient nested objects for you.",[250,1323,1325],{"id":1324},"_3-many-to-many-relations-via-junction-table","3. Many-to-Many Relations (via Junction Table)",[243,1327,1328,1329,1332],{},"Many-to-many relationships require a ",[284,1330,1331],{},"junction table"," (also called a pivot or join table) that connects two tables. For example, posts can have many tags, and tags can be on many posts.",[243,1334,1335,1336,1339,1340,272,1342,1344,1345,1347,1348,475],{},"In the v1 ",[258,1337,1338],{},"relations()"," API, model many-to-many by defining ",[258,1341,271],{},[258,1343,275],{}," on the junction table, then use nested ",[258,1346,975],{}," with ",[258,1349,1350],{},"with",[339,1352,1354],{"id":1353},"example-posts-and-tags","Example: Posts and Tags",[353,1356,1358],{"className":355,"code":1357,"language":357,"meta":358,"style":358},"// src/lib/db/schema.ts\nimport { sqliteTable, text, integer, relations } from '@type32/tauri-sqlite-orm';\n\n// ---- Tables ----\nexport const posts = sqliteTable('posts', {\n  id: integer('id').primaryKey().autoincrement(),\n  title: text('title').notNull(),\n  authorId: integer('author_id').notNull().references(() => users._.columns.id),\n});\n\nexport const tags = sqliteTable('tags', {\n  id: integer('id').primaryKey().autoincrement(),\n  name: text('name').notNull().unique(),\n});\n\n// Junction table for posts ↔ tags\nexport const postTags = sqliteTable('post_tags', {\n  postId: integer('post_id').notNull().references(() => posts._.columns.id),\n  tagId: integer('tag_id').notNull().references(() => tags._.columns.id),\n});\n\n// ---- Relations ----\n\nexport const postsRelations = relations(posts, ({ one, many }) => ({\n  user: one(users, {\n    fields: [posts._.columns.authorId],\n    references: [users._.columns.id],\n  }),\n  postTags: many(postTags),\n}));\n\nexport const postTagsRelations = relations(postTags, ({ one }) => ({\n  post: one(posts, {\n    fields: [postTags._.columns.postId],\n    references: [posts._.columns.id],\n  }),\n  tag: one(tags, {\n    fields: [postTags._.columns.tagId],\n    references: [tags._.columns.id],\n  }),\n}));\n\nexport const tagsRelations = relations(tags, ({ many }) => ({\n  postTags: many(postTags),\n}));\n",[258,1359,1360,1364,1396,1400,1404,1428,1460,1486,1536,1544,1548,1574,1606,1641,1649,1653,1658,1684,1736,1789,1797,1801,1805,1809,1841,1856,1878,1900,1908,1922,1930,1934,1964,1979,2003,2025,2033,2050,2074,2098,2107,2116,2121,2151,2164],{"__ignoreMap":358},[362,1361,1362],{"class":364,"line":365},[362,1363,369],{"class":368},[362,1365,1366,1368,1370,1372,1374,1376,1378,1380,1382,1384,1386,1388,1390,1392,1394],{"class":364,"line":372},[362,1367,376],{"class":375},[362,1369,380],{"class":379},[362,1371,384],{"class":383},[362,1373,387],{"class":379},[362,1375,390],{"class":383},[362,1377,387],{"class":379},[362,1379,395],{"class":383},[362,1381,387],{"class":379},[362,1383,400],{"class":383},[362,1385,403],{"class":379},[362,1387,406],{"class":375},[362,1389,409],{"class":379},[362,1391,413],{"class":412},[362,1393,416],{"class":379},[362,1395,419],{"class":379},[362,1397,1398],{"class":364,"line":422},[362,1399,426],{"emptyLinePlaceholder":425},[362,1401,1402],{"class":364,"line":429},[362,1403,432],{"class":368},[362,1405,1406,1408,1410,1412,1414,1416,1418,1420,1422,1424,1426],{"class":364,"line":435},[362,1407,438],{"class":375},[362,1409,442],{"class":441},[362,1411,562],{"class":383},[362,1413,448],{"class":379},[362,1415,384],{"class":451},[362,1417,454],{"class":383},[362,1419,416],{"class":379},[362,1421,351],{"class":412},[362,1423,416],{"class":379},[362,1425,387],{"class":379},[362,1427,465],{"class":379},[362,1429,1430,1432,1434,1436,1438,1440,1442,1444,1446,1448,1450,1452,1454,1456,1458],{"class":364,"line":468},[362,1431,472],{"class":471},[362,1433,475],{"class":379},[362,1435,395],{"class":451},[362,1437,454],{"class":383},[362,1439,416],{"class":379},[362,1441,484],{"class":412},[362,1443,416],{"class":379},[362,1445,489],{"class":383},[362,1447,276],{"class":379},[362,1449,494],{"class":451},[362,1451,497],{"class":383},[362,1453,276],{"class":379},[362,1455,502],{"class":451},[362,1457,497],{"class":383},[362,1459,507],{"class":379},[362,1461,1462,1464,1466,1468,1470,1472,1474,1476,1478,1480,1482,1484],{"class":364,"line":510},[362,1463,617],{"class":471},[362,1465,475],{"class":379},[362,1467,390],{"class":451},[362,1469,454],{"class":383},[362,1471,416],{"class":379},[362,1473,628],{"class":412},[362,1475,416],{"class":379},[362,1477,489],{"class":383},[362,1479,276],{"class":379},[362,1481,533],{"class":451},[362,1483,497],{"class":383},[362,1485,507],{"class":379},[362,1487,1488,1490,1492,1494,1496,1498,1500,1502,1504,1506,1508,1510,1512,1514,1516,1518,1520,1522,1524,1526,1528,1530,1532,1534],{"class":364,"line":540},[362,1489,646],{"class":471},[362,1491,475],{"class":379},[362,1493,395],{"class":451},[362,1495,454],{"class":383},[362,1497,416],{"class":379},[362,1499,657],{"class":412},[362,1501,416],{"class":379},[362,1503,489],{"class":383},[362,1505,276],{"class":379},[362,1507,533],{"class":451},[362,1509,497],{"class":383},[362,1511,276],{"class":379},[362,1513,303],{"class":451},[362,1515,454],{"class":383},[362,1517,497],{"class":379},[362,1519,678],{"class":441},[362,1521,681],{"class":383},[362,1523,276],{"class":379},[362,1525,686],{"class":383},[362,1527,276],{"class":379},[362,1529,691],{"class":383},[362,1531,276],{"class":379},[362,1533,696],{"class":383},[362,1535,507],{"class":379},[362,1537,1538,1540,1542],{"class":364,"line":550},[362,1539,543],{"class":379},[362,1541,489],{"class":383},[362,1543,419],{"class":379},[362,1545,1546],{"class":364,"line":555},[362,1547,426],{"emptyLinePlaceholder":425},[362,1549,1550,1552,1554,1557,1559,1561,1563,1565,1568,1570,1572],{"class":364,"line":581},[362,1551,438],{"class":375},[362,1553,442],{"class":441},[362,1555,1556],{"class":383}," tags ",[362,1558,448],{"class":379},[362,1560,384],{"class":451},[362,1562,454],{"class":383},[362,1564,416],{"class":379},[362,1566,1567],{"class":412},"tags",[362,1569,416],{"class":379},[362,1571,387],{"class":379},[362,1573,465],{"class":379},[362,1575,1576,1578,1580,1582,1584,1586,1588,1590,1592,1594,1596,1598,1600,1602,1604],{"class":364,"line":614},[362,1577,472],{"class":471},[362,1579,475],{"class":379},[362,1581,395],{"class":451},[362,1583,454],{"class":383},[362,1585,416],{"class":379},[362,1587,484],{"class":412},[362,1589,416],{"class":379},[362,1591,489],{"class":383},[362,1593,276],{"class":379},[362,1595,494],{"class":451},[362,1597,497],{"class":383},[362,1599,276],{"class":379},[362,1601,502],{"class":451},[362,1603,497],{"class":383},[362,1605,507],{"class":379},[362,1607,1608,1611,1613,1615,1617,1619,1622,1624,1626,1628,1630,1632,1634,1637,1639],{"class":364,"line":643},[362,1609,1610],{"class":471},"  name",[362,1612,475],{"class":379},[362,1614,390],{"class":451},[362,1616,454],{"class":383},[362,1618,416],{"class":379},[362,1620,1621],{"class":412},"name",[362,1623,416],{"class":379},[362,1625,489],{"class":383},[362,1627,276],{"class":379},[362,1629,533],{"class":451},[362,1631,497],{"class":383},[362,1633,276],{"class":379},[362,1635,1636],{"class":451},"unique",[362,1638,497],{"class":383},[362,1640,507],{"class":379},[362,1642,1643,1645,1647],{"class":364,"line":701},[362,1644,543],{"class":379},[362,1646,489],{"class":383},[362,1648,419],{"class":379},[362,1650,1651],{"class":364,"line":710},[362,1652,426],{"emptyLinePlaceholder":425},[362,1654,1655],{"class":364,"line":715},[362,1656,1657],{"class":368},"// Junction table for posts ↔ tags\n",[362,1659,1660,1662,1664,1667,1669,1671,1673,1675,1678,1680,1682],{"class":364,"line":720},[362,1661,438],{"class":375},[362,1663,442],{"class":441},[362,1665,1666],{"class":383}," postTags ",[362,1668,448],{"class":379},[362,1670,384],{"class":451},[362,1672,454],{"class":383},[362,1674,416],{"class":379},[362,1676,1677],{"class":412},"post_tags",[362,1679,416],{"class":379},[362,1681,387],{"class":379},[362,1683,465],{"class":379},[362,1685,1686,1689,1691,1693,1695,1697,1700,1702,1704,1706,1708,1710,1712,1714,1716,1718,1720,1722,1724,1726,1728,1730,1732,1734],{"class":364,"line":726},[362,1687,1688],{"class":471},"  postId",[362,1690,475],{"class":379},[362,1692,395],{"class":451},[362,1694,454],{"class":383},[362,1696,416],{"class":379},[362,1698,1699],{"class":412},"post_id",[362,1701,416],{"class":379},[362,1703,489],{"class":383},[362,1705,276],{"class":379},[362,1707,533],{"class":451},[362,1709,497],{"class":383},[362,1711,276],{"class":379},[362,1713,303],{"class":451},[362,1715,454],{"class":383},[362,1717,497],{"class":379},[362,1719,678],{"class":441},[362,1721,1070],{"class":383},[362,1723,276],{"class":379},[362,1725,686],{"class":383},[362,1727,276],{"class":379},[362,1729,691],{"class":383},[362,1731,276],{"class":379},[362,1733,696],{"class":383},[362,1735,507],{"class":379},[362,1737,1738,1741,1743,1745,1747,1749,1752,1754,1756,1758,1760,1762,1764,1766,1768,1770,1772,1775,1777,1779,1781,1783,1785,1787],{"class":364,"line":731},[362,1739,1740],{"class":471},"  tagId",[362,1742,475],{"class":379},[362,1744,395],{"class":451},[362,1746,454],{"class":383},[362,1748,416],{"class":379},[362,1750,1751],{"class":412},"tag_id",[362,1753,416],{"class":379},[362,1755,489],{"class":383},[362,1757,276],{"class":379},[362,1759,533],{"class":451},[362,1761,497],{"class":383},[362,1763,276],{"class":379},[362,1765,303],{"class":451},[362,1767,454],{"class":383},[362,1769,497],{"class":379},[362,1771,678],{"class":441},[362,1773,1774],{"class":383}," tags",[362,1776,276],{"class":379},[362,1778,686],{"class":383},[362,1780,276],{"class":379},[362,1782,691],{"class":383},[362,1784,276],{"class":379},[362,1786,696],{"class":383},[362,1788,507],{"class":379},[362,1790,1791,1793,1795],{"class":364,"line":737},[362,1792,543],{"class":379},[362,1794,489],{"class":383},[362,1796,419],{"class":379},[362,1798,1799],{"class":364,"line":774},[362,1800,426],{"emptyLinePlaceholder":425},[362,1802,1803],{"class":364,"line":780},[362,1804,723],{"class":368},[362,1806,1807],{"class":364,"line":786},[362,1808,426],{"emptyLinePlaceholder":425},[362,1810,1811,1813,1815,1817,1819,1821,1823,1825,1827,1829,1831,1833,1835,1837,1839],{"class":364,"line":792},[362,1812,438],{"class":375},[362,1814,442],{"class":441},[362,1816,744],{"class":383},[362,1818,448],{"class":379},[362,1820,400],{"class":451},[362,1822,751],{"class":383},[362,1824,387],{"class":379},[362,1826,756],{"class":379},[362,1828,760],{"class":759},[362,1830,387],{"class":379},[362,1832,912],{"class":759},[362,1834,763],{"class":379},[362,1836,678],{"class":441},[362,1838,768],{"class":383},[362,1840,771],{"class":379},[362,1842,1843,1846,1848,1850,1852,1854],{"class":364,"line":809},[362,1844,1845],{"class":471},"  user",[362,1847,475],{"class":379},[362,1849,760],{"class":451},[362,1851,802],{"class":383},[362,1853,387],{"class":379},[362,1855,465],{"class":379},[362,1857,1858,1860,1862,1864,1866,1868,1870,1872,1874,1876],{"class":364,"line":835},[362,1859,812],{"class":471},[362,1861,475],{"class":379},[362,1863,817],{"class":383},[362,1865,276],{"class":379},[362,1867,686],{"class":383},[362,1869,276],{"class":379},[362,1871,691],{"class":383},[362,1873,276],{"class":379},[362,1875,830],{"class":383},[362,1877,507],{"class":379},[362,1879,1880,1882,1884,1886,1888,1890,1892,1894,1896,1898],{"class":364,"line":861},[362,1881,838],{"class":471},[362,1883,475],{"class":379},[362,1885,843],{"class":383},[362,1887,276],{"class":379},[362,1889,686],{"class":383},[362,1891,276],{"class":379},[362,1893,691],{"class":383},[362,1895,276],{"class":379},[362,1897,856],{"class":383},[362,1899,507],{"class":379},[362,1901,1902,1904,1906],{"class":364,"line":871},[362,1903,864],{"class":379},[362,1905,489],{"class":383},[362,1907,507],{"class":379},[362,1909,1910,1913,1915,1917,1920],{"class":364,"line":881},[362,1911,1912],{"class":471},"  postTags",[362,1914,475],{"class":379},[362,1916,912],{"class":451},[362,1918,1919],{"class":383},"(postTags)",[362,1921,507],{"class":379},[362,1923,1924,1926,1928],{"class":364,"line":886},[362,1925,543],{"class":379},[362,1927,876],{"class":383},[362,1929,419],{"class":379},[362,1931,1932],{"class":364,"line":892},[362,1933,426],{"emptyLinePlaceholder":425},[362,1935,1936,1938,1940,1943,1945,1947,1950,1952,1954,1956,1958,1960,1962],{"class":364,"line":923},[362,1937,438],{"class":375},[362,1939,442],{"class":441},[362,1941,1942],{"class":383}," postTagsRelations ",[362,1944,448],{"class":379},[362,1946,400],{"class":451},[362,1948,1949],{"class":383},"(postTags",[362,1951,387],{"class":379},[362,1953,756],{"class":379},[362,1955,760],{"class":759},[362,1957,763],{"class":379},[362,1959,678],{"class":441},[362,1961,768],{"class":383},[362,1963,771],{"class":379},[362,1965,1966,1969,1971,1973,1975,1977],{"class":364,"line":929},[362,1967,1968],{"class":471},"  post",[362,1970,475],{"class":379},[362,1972,760],{"class":451},[362,1974,751],{"class":383},[362,1976,387],{"class":379},[362,1978,465],{"class":379},[362,1980,1981,1983,1985,1988,1990,1992,1994,1996,1998,2001],{"class":364,"line":935},[362,1982,812],{"class":471},[362,1984,475],{"class":379},[362,1986,1987],{"class":383}," [postTags",[362,1989,276],{"class":379},[362,1991,686],{"class":383},[362,1993,276],{"class":379},[362,1995,691],{"class":383},[362,1997,276],{"class":379},[362,1999,2000],{"class":383},"postId]",[362,2002,507],{"class":379},[362,2004,2005,2007,2009,2011,2013,2015,2017,2019,2021,2023],{"class":364,"line":941},[362,2006,838],{"class":471},[362,2008,475],{"class":379},[362,2010,817],{"class":383},[362,2012,276],{"class":379},[362,2014,686],{"class":383},[362,2016,276],{"class":379},[362,2018,691],{"class":383},[362,2020,276],{"class":379},[362,2022,856],{"class":383},[362,2024,507],{"class":379},[362,2026,2027,2029,2031],{"class":364,"line":956},[362,2028,864],{"class":379},[362,2030,489],{"class":383},[362,2032,507],{"class":379},[362,2034,2036,2039,2041,2043,2046,2048],{"class":364,"line":2035},37,[362,2037,2038],{"class":471},"  tag",[362,2040,475],{"class":379},[362,2042,760],{"class":451},[362,2044,2045],{"class":383},"(tags",[362,2047,387],{"class":379},[362,2049,465],{"class":379},[362,2051,2053,2055,2057,2059,2061,2063,2065,2067,2069,2072],{"class":364,"line":2052},38,[362,2054,812],{"class":471},[362,2056,475],{"class":379},[362,2058,1987],{"class":383},[362,2060,276],{"class":379},[362,2062,686],{"class":383},[362,2064,276],{"class":379},[362,2066,691],{"class":383},[362,2068,276],{"class":379},[362,2070,2071],{"class":383},"tagId]",[362,2073,507],{"class":379},[362,2075,2077,2079,2081,2084,2086,2088,2090,2092,2094,2096],{"class":364,"line":2076},39,[362,2078,838],{"class":471},[362,2080,475],{"class":379},[362,2082,2083],{"class":383}," [tags",[362,2085,276],{"class":379},[362,2087,686],{"class":383},[362,2089,276],{"class":379},[362,2091,691],{"class":383},[362,2093,276],{"class":379},[362,2095,856],{"class":383},[362,2097,507],{"class":379},[362,2099,2101,2103,2105],{"class":364,"line":2100},40,[362,2102,864],{"class":379},[362,2104,489],{"class":383},[362,2106,507],{"class":379},[362,2108,2110,2112,2114],{"class":364,"line":2109},41,[362,2111,543],{"class":379},[362,2113,876],{"class":383},[362,2115,419],{"class":379},[362,2117,2119],{"class":364,"line":2118},42,[362,2120,426],{"emptyLinePlaceholder":425},[362,2122,2124,2126,2128,2131,2133,2135,2137,2139,2141,2143,2145,2147,2149],{"class":364,"line":2123},43,[362,2125,438],{"class":375},[362,2127,442],{"class":441},[362,2129,2130],{"class":383}," tagsRelations ",[362,2132,448],{"class":379},[362,2134,400],{"class":451},[362,2136,2045],{"class":383},[362,2138,387],{"class":379},[362,2140,756],{"class":379},[362,2142,912],{"class":759},[362,2144,763],{"class":379},[362,2146,678],{"class":441},[362,2148,768],{"class":383},[362,2150,771],{"class":379},[362,2152,2154,2156,2158,2160,2162],{"class":364,"line":2153},44,[362,2155,1912],{"class":471},[362,2157,475],{"class":379},[362,2159,912],{"class":451},[362,2161,1919],{"class":383},[362,2163,507],{"class":379},[362,2165,2167,2169,2171],{"class":364,"line":2166},45,[362,2168,543],{"class":379},[362,2170,876],{"class":383},[362,2172,419],{"class":379},[339,2174,2176],{"id":2175},"querying-many-to-many-relations","Querying Many-to-Many Relations",[243,2178,2179,2180,1347,2182,2184],{},"Use nested ",[258,2181,975],{},[258,2183,1350],{}," to load through the junction:",[353,2186,2188],{"className":993,"code":2187,"language":995,"meta":358,"style":358},"// Fetch posts with their tags (via postTags junction)\nconst postsWithTags = await db.select(posts)\n  .include({\n    postTags: {\n      with: { tag: true },\n    },\n  })\n  .all();\n\n/*\nResult Shape:\n[\n  {\n    id: 1,\n    title: 'My Post',\n    postTags: [\n      { postId: 1, tagId: 1, tag: { id: 1, name: 'javascript' } },\n      { postId: 1, tagId: 2, tag: { id: 2, name: 'typescript' } }\n    ]\n  }\n]\n*/\n",[258,2189,2190,2195,2214,2224,2233,2252,2257,2264,2275,2279,2283,2287,2292,2297,2301,2306,2311,2316,2321,2326,2330,2335],{"__ignoreMap":358},[362,2191,2192],{"class":364,"line":365},[362,2193,2194],{"class":368},"// Fetch posts with their tags (via postTags junction)\n",[362,2196,2197,2199,2202,2204,2206,2208,2210,2212],{"class":364,"line":372},[362,2198,1002],{"class":441},[362,2200,2201],{"class":383}," postsWithTags ",[362,2203,448],{"class":379},[362,2205,1010],{"class":375},[362,2207,1013],{"class":383},[362,2209,276],{"class":379},[362,2211,979],{"class":451},[362,2213,1187],{"class":383},[362,2215,2216,2218,2220,2222],{"class":364,"line":422},[362,2217,1025],{"class":379},[362,2219,969],{"class":451},[362,2221,454],{"class":383},[362,2223,771],{"class":379},[362,2225,2226,2229,2231],{"class":364,"line":429},[362,2227,2228],{"class":471},"    postTags",[362,2230,475],{"class":379},[362,2232,465],{"class":379},[362,2234,2235,2238,2240,2242,2245,2247,2249],{"class":364,"line":435},[362,2236,2237],{"class":471},"      with",[362,2239,475],{"class":379},[362,2241,380],{"class":379},[362,2243,2244],{"class":471}," tag",[362,2246,475],{"class":379},[362,2248,1076],{"class":1075},[362,2250,2251],{"class":379}," },\n",[362,2253,2254],{"class":364,"line":468},[362,2255,2256],{"class":379},"    },\n",[362,2258,2259,2261],{"class":364,"line":510},[362,2260,864],{"class":379},[362,2262,2263],{"class":383},")\n",[362,2265,2266,2268,2271,2273],{"class":364,"line":540},[362,2267,1025],{"class":379},[362,2269,2270],{"class":451},"all",[362,2272,497],{"class":383},[362,2274,419],{"class":379},[362,2276,2277],{"class":364,"line":550},[362,2278,426],{"emptyLinePlaceholder":425},[362,2280,2281],{"class":364,"line":555},[362,2282,1104],{"class":368},[362,2284,2285],{"class":364,"line":581},[362,2286,1109],{"class":368},[362,2288,2289],{"class":364,"line":614},[362,2290,2291],{"class":368},"[\n",[362,2293,2294],{"class":364,"line":643},[362,2295,2296],{"class":368},"  {\n",[362,2298,2299],{"class":364,"line":701},[362,2300,1293],{"class":368},[362,2302,2303],{"class":364,"line":710},[362,2304,2305],{"class":368},"    title: 'My Post',\n",[362,2307,2308],{"class":364,"line":715},[362,2309,2310],{"class":368},"    postTags: [\n",[362,2312,2313],{"class":364,"line":720},[362,2314,2315],{"class":368},"      { postId: 1, tagId: 1, tag: { id: 1, name: 'javascript' } },\n",[362,2317,2318],{"class":364,"line":726},[362,2319,2320],{"class":368},"      { postId: 1, tagId: 2, tag: { id: 2, name: 'typescript' } }\n",[362,2322,2323],{"class":364,"line":731},[362,2324,2325],{"class":368},"    ]\n",[362,2327,2328],{"class":364,"line":737},[362,2329,1303],{"class":368},[362,2331,2332],{"class":364,"line":774},[362,2333,2334],{"class":368},"]\n",[362,2336,2337],{"class":364,"line":780},[362,2338,1153],{"class":368},[243,2340,2341,2342,2345,2346,1347,2349,2351,2352,2356],{},"For a direct ",[258,2343,2344],{},"posts.include({ tags: true })"," without nested junction data, use the ",[284,2347,2348],{},"Relations v2 API",[258,2350,337],{},"—see ",[2353,2354,2348],"a",{"href":2355},"#4-relations-v2-api-definerelations"," below.",[339,2358,2360],{"id":2359},"adding-data-to-many-to-many-relations","Adding Data to Many-to-Many Relations",[243,2362,2363],{},"Insert records into the junction table:",[353,2365,2367],{"className":993,"code":2366,"language":995,"meta":358,"style":358},"// First, create posts and tags\nconst post = await db.insert(posts)\n  .values({ title: 'My Post', authorId: userId })\n  .returningFirst();\n\nconst tag = await db.insert(tags)\n  .values({ name: 'typescript' })\n  .returningFirst();\n\n// Then create the relationship via the junction table\nawait db.insert(postTags)\n  .values({ postId: post!.id, tagId: tag!.id })\n  .execute();\n",[258,2368,2369,2374,2394,2431,2442,2446,2466,2491,2501,2505,2510,2524,2565],{"__ignoreMap":358},[362,2370,2371],{"class":364,"line":365},[362,2372,2373],{"class":368},"// First, create posts and tags\n",[362,2375,2376,2378,2381,2383,2385,2387,2389,2392],{"class":364,"line":372},[362,2377,1002],{"class":441},[362,2379,2380],{"class":383}," post ",[362,2382,448],{"class":379},[362,2384,1010],{"class":375},[362,2386,1013],{"class":383},[362,2388,276],{"class":379},[362,2390,2391],{"class":451},"insert",[362,2393,1187],{"class":383},[362,2395,2396,2398,2401,2403,2405,2408,2410,2412,2415,2417,2419,2422,2424,2427,2429],{"class":364,"line":422},[362,2397,1025],{"class":379},[362,2399,2400],{"class":451},"values",[362,2402,454],{"class":383},[362,2404,1067],{"class":379},[362,2406,2407],{"class":471}," title",[362,2409,475],{"class":379},[362,2411,409],{"class":379},[362,2413,2414],{"class":412},"My Post",[362,2416,416],{"class":379},[362,2418,387],{"class":379},[362,2420,2421],{"class":471}," authorId",[362,2423,475],{"class":379},[362,2425,2426],{"class":383}," userId ",[362,2428,543],{"class":379},[362,2430,2263],{"class":383},[362,2432,2433,2435,2438,2440],{"class":364,"line":429},[362,2434,1025],{"class":379},[362,2436,2437],{"class":451},"returningFirst",[362,2439,497],{"class":383},[362,2441,419],{"class":379},[362,2443,2444],{"class":364,"line":435},[362,2445,426],{"emptyLinePlaceholder":425},[362,2447,2448,2450,2453,2455,2457,2459,2461,2463],{"class":364,"line":468},[362,2449,1002],{"class":441},[362,2451,2452],{"class":383}," tag ",[362,2454,448],{"class":379},[362,2456,1010],{"class":375},[362,2458,1013],{"class":383},[362,2460,276],{"class":379},[362,2462,2391],{"class":451},[362,2464,2465],{"class":383},"(tags)\n",[362,2467,2468,2470,2472,2474,2476,2479,2481,2483,2485,2487,2489],{"class":364,"line":510},[362,2469,1025],{"class":379},[362,2471,2400],{"class":451},[362,2473,454],{"class":383},[362,2475,1067],{"class":379},[362,2477,2478],{"class":471}," name",[362,2480,475],{"class":379},[362,2482,409],{"class":379},[362,2484,357],{"class":412},[362,2486,416],{"class":379},[362,2488,403],{"class":379},[362,2490,2263],{"class":383},[362,2492,2493,2495,2497,2499],{"class":364,"line":540},[362,2494,1025],{"class":379},[362,2496,2437],{"class":451},[362,2498,497],{"class":383},[362,2500,419],{"class":379},[362,2502,2503],{"class":364,"line":550},[362,2504,426],{"emptyLinePlaceholder":425},[362,2506,2507],{"class":364,"line":555},[362,2508,2509],{"class":368},"// Then create the relationship via the junction table\n",[362,2511,2512,2515,2517,2519,2521],{"class":364,"line":581},[362,2513,2514],{"class":375},"await",[362,2516,1013],{"class":383},[362,2518,276],{"class":379},[362,2520,2391],{"class":451},[362,2522,2523],{"class":383},"(postTags)\n",[362,2525,2526,2528,2530,2532,2534,2537,2539,2542,2545,2547,2549,2552,2554,2556,2558,2561,2563],{"class":364,"line":614},[362,2527,1025],{"class":379},[362,2529,2400],{"class":451},[362,2531,454],{"class":383},[362,2533,1067],{"class":379},[362,2535,2536],{"class":471}," postId",[362,2538,475],{"class":379},[362,2540,2541],{"class":383}," post",[362,2543,2544],{"class":379},"!.",[362,2546,484],{"class":383},[362,2548,387],{"class":379},[362,2550,2551],{"class":471}," tagId",[362,2553,475],{"class":379},[362,2555,2244],{"class":383},[362,2557,2544],{"class":379},[362,2559,2560],{"class":383},"id ",[362,2562,543],{"class":379},[362,2564,2263],{"class":383},[362,2566,2567,2569,2572,2574],{"class":364,"line":643},[362,2568,1025],{"class":379},[362,2570,2571],{"class":451},"execute",[362,2573,497],{"class":383},[362,2575,419],{"class":379},[250,2577,2579],{"id":2578},"_4-relations-v2-api-definerelations","4. Relations v2 API (defineRelations)",[243,2581,2582,2583,2586,2587,2590,2591,475],{},"For a Drizzle-style single-place definition with ",[258,2584,2585],{},"from","/",[258,2588,2589],{},"to"," and many-without-one support, use ",[258,2592,333],{},[353,2594,2596],{"className":993,"code":2595,"language":995,"meta":358,"style":358},"import { sqliteTable, integer, text, defineRelations } from '@type32/tauri-sqlite-orm';\n\nexport const users = sqliteTable('users', {\n  id: integer('id').primaryKey().autoincrement(),\n  fullName: text('full_name').notNull(),\n});\n\nexport const posts = sqliteTable('posts', {\n  id: integer('id').primaryKey().autoincrement(),\n  title: text('title').notNull(),\n  authorId: integer('author_id').notNull().references(() => users._.columns.id),\n});\n\nconst schema = { users, posts };\n\ndefineRelations(schema, (r) => ({\n  users: {\n    posts: r.many.posts({ from: r.users.id, to: r.posts.authorId }),\n  },\n  posts: {\n    author: r.one.users({ from: r.posts.authorId, to: r.users.id }),\n  },\n}));\n\n// Pass schema to TauriORM - relations are already applied to tables\nconst orm = new TauriORM(db, schema);\n",[258,2597,2598,2631,2635,2659,2691,2717,2725,2729,2753,2785,2811,2861,2869,2873,2893,2897,2919,2928,2988,2993,3001,3059,3063,3071,3075,3080],{"__ignoreMap":358},[362,2599,2600,2602,2604,2606,2608,2610,2612,2614,2616,2619,2621,2623,2625,2627,2629],{"class":364,"line":365},[362,2601,376],{"class":375},[362,2603,380],{"class":379},[362,2605,384],{"class":383},[362,2607,387],{"class":379},[362,2609,395],{"class":383},[362,2611,387],{"class":379},[362,2613,390],{"class":383},[362,2615,387],{"class":379},[362,2617,2618],{"class":383}," defineRelations",[362,2620,403],{"class":379},[362,2622,406],{"class":375},[362,2624,409],{"class":379},[362,2626,413],{"class":412},[362,2628,416],{"class":379},[362,2630,419],{"class":379},[362,2632,2633],{"class":364,"line":372},[362,2634,426],{"emptyLinePlaceholder":425},[362,2636,2637,2639,2641,2643,2645,2647,2649,2651,2653,2655,2657],{"class":364,"line":422},[362,2638,438],{"class":375},[362,2640,442],{"class":441},[362,2642,445],{"class":383},[362,2644,448],{"class":379},[362,2646,384],{"class":451},[362,2648,454],{"class":383},[362,2650,416],{"class":379},[362,2652,348],{"class":412},[362,2654,416],{"class":379},[362,2656,387],{"class":379},[362,2658,465],{"class":379},[362,2660,2661,2663,2665,2667,2669,2671,2673,2675,2677,2679,2681,2683,2685,2687,2689],{"class":364,"line":429},[362,2662,472],{"class":471},[362,2664,475],{"class":379},[362,2666,395],{"class":451},[362,2668,454],{"class":383},[362,2670,416],{"class":379},[362,2672,484],{"class":412},[362,2674,416],{"class":379},[362,2676,489],{"class":383},[362,2678,276],{"class":379},[362,2680,494],{"class":451},[362,2682,497],{"class":383},[362,2684,276],{"class":379},[362,2686,502],{"class":451},[362,2688,497],{"class":383},[362,2690,507],{"class":379},[362,2692,2693,2695,2697,2699,2701,2703,2705,2707,2709,2711,2713,2715],{"class":364,"line":435},[362,2694,513],{"class":471},[362,2696,475],{"class":379},[362,2698,390],{"class":451},[362,2700,454],{"class":383},[362,2702,416],{"class":379},[362,2704,524],{"class":412},[362,2706,416],{"class":379},[362,2708,489],{"class":383},[362,2710,276],{"class":379},[362,2712,533],{"class":451},[362,2714,497],{"class":383},[362,2716,507],{"class":379},[362,2718,2719,2721,2723],{"class":364,"line":468},[362,2720,543],{"class":379},[362,2722,489],{"class":383},[362,2724,419],{"class":379},[362,2726,2727],{"class":364,"line":510},[362,2728,426],{"emptyLinePlaceholder":425},[362,2730,2731,2733,2735,2737,2739,2741,2743,2745,2747,2749,2751],{"class":364,"line":540},[362,2732,438],{"class":375},[362,2734,442],{"class":441},[362,2736,562],{"class":383},[362,2738,448],{"class":379},[362,2740,384],{"class":451},[362,2742,454],{"class":383},[362,2744,416],{"class":379},[362,2746,351],{"class":412},[362,2748,416],{"class":379},[362,2750,387],{"class":379},[362,2752,465],{"class":379},[362,2754,2755,2757,2759,2761,2763,2765,2767,2769,2771,2773,2775,2777,2779,2781,2783],{"class":364,"line":550},[362,2756,472],{"class":471},[362,2758,475],{"class":379},[362,2760,395],{"class":451},[362,2762,454],{"class":383},[362,2764,416],{"class":379},[362,2766,484],{"class":412},[362,2768,416],{"class":379},[362,2770,489],{"class":383},[362,2772,276],{"class":379},[362,2774,494],{"class":451},[362,2776,497],{"class":383},[362,2778,276],{"class":379},[362,2780,502],{"class":451},[362,2782,497],{"class":383},[362,2784,507],{"class":379},[362,2786,2787,2789,2791,2793,2795,2797,2799,2801,2803,2805,2807,2809],{"class":364,"line":555},[362,2788,617],{"class":471},[362,2790,475],{"class":379},[362,2792,390],{"class":451},[362,2794,454],{"class":383},[362,2796,416],{"class":379},[362,2798,628],{"class":412},[362,2800,416],{"class":379},[362,2802,489],{"class":383},[362,2804,276],{"class":379},[362,2806,533],{"class":451},[362,2808,497],{"class":383},[362,2810,507],{"class":379},[362,2812,2813,2815,2817,2819,2821,2823,2825,2827,2829,2831,2833,2835,2837,2839,2841,2843,2845,2847,2849,2851,2853,2855,2857,2859],{"class":364,"line":581},[362,2814,646],{"class":471},[362,2816,475],{"class":379},[362,2818,395],{"class":451},[362,2820,454],{"class":383},[362,2822,416],{"class":379},[362,2824,657],{"class":412},[362,2826,416],{"class":379},[362,2828,489],{"class":383},[362,2830,276],{"class":379},[362,2832,533],{"class":451},[362,2834,497],{"class":383},[362,2836,276],{"class":379},[362,2838,303],{"class":451},[362,2840,454],{"class":383},[362,2842,497],{"class":379},[362,2844,678],{"class":441},[362,2846,681],{"class":383},[362,2848,276],{"class":379},[362,2850,686],{"class":383},[362,2852,276],{"class":379},[362,2854,691],{"class":383},[362,2856,276],{"class":379},[362,2858,696],{"class":383},[362,2860,507],{"class":379},[362,2862,2863,2865,2867],{"class":364,"line":614},[362,2864,543],{"class":379},[362,2866,489],{"class":383},[362,2868,419],{"class":379},[362,2870,2871],{"class":364,"line":643},[362,2872,426],{"emptyLinePlaceholder":425},[362,2874,2875,2877,2880,2882,2884,2886,2888,2890],{"class":364,"line":701},[362,2876,1002],{"class":441},[362,2878,2879],{"class":383}," schema ",[362,2881,448],{"class":379},[362,2883,380],{"class":379},[362,2885,681],{"class":383},[362,2887,387],{"class":379},[362,2889,562],{"class":383},[362,2891,2892],{"class":379},"};\n",[362,2894,2895],{"class":364,"line":710},[362,2896,426],{"emptyLinePlaceholder":425},[362,2898,2899,2901,2904,2906,2908,2911,2913,2915,2917],{"class":364,"line":715},[362,2900,333],{"class":451},[362,2902,2903],{"class":383},"(schema",[362,2905,387],{"class":379},[362,2907,768],{"class":379},[362,2909,2910],{"class":759},"r",[362,2912,489],{"class":379},[362,2914,678],{"class":441},[362,2916,768],{"class":383},[362,2918,771],{"class":379},[362,2920,2921,2924,2926],{"class":364,"line":720},[362,2922,2923],{"class":471},"  users",[362,2925,475],{"class":379},[362,2927,465],{"class":379},[362,2929,2930,2933,2935,2938,2940,2942,2944,2946,2948,2950,2952,2954,2956,2958,2960,2962,2964,2966,2969,2971,2973,2975,2977,2979,2982,2984,2986],{"class":364,"line":726},[362,2931,2932],{"class":471},"    posts",[362,2934,475],{"class":379},[362,2936,2937],{"class":383}," r",[362,2939,276],{"class":379},[362,2941,275],{"class":383},[362,2943,276],{"class":379},[362,2945,351],{"class":451},[362,2947,454],{"class":383},[362,2949,1067],{"class":379},[362,2951,406],{"class":471},[362,2953,475],{"class":379},[362,2955,2937],{"class":383},[362,2957,276],{"class":379},[362,2959,348],{"class":383},[362,2961,276],{"class":379},[362,2963,484],{"class":383},[362,2965,387],{"class":379},[362,2967,2968],{"class":471}," to",[362,2970,475],{"class":379},[362,2972,2937],{"class":383},[362,2974,276],{"class":379},[362,2976,351],{"class":383},[362,2978,276],{"class":379},[362,2980,2981],{"class":383},"authorId ",[362,2983,543],{"class":379},[362,2985,489],{"class":383},[362,2987,507],{"class":379},[362,2989,2990],{"class":364,"line":731},[362,2991,2992],{"class":379},"  },\n",[362,2994,2995,2997,2999],{"class":364,"line":737},[362,2996,944],{"class":471},[362,2998,475],{"class":379},[362,3000,465],{"class":379},[362,3002,3003,3006,3008,3010,3012,3014,3016,3018,3020,3022,3024,3026,3028,3030,3032,3034,3037,3039,3041,3043,3045,3047,3049,3051,3053,3055,3057],{"class":364,"line":774},[362,3004,3005],{"class":471},"    author",[362,3007,475],{"class":379},[362,3009,2937],{"class":383},[362,3011,276],{"class":379},[362,3013,271],{"class":383},[362,3015,276],{"class":379},[362,3017,348],{"class":451},[362,3019,454],{"class":383},[362,3021,1067],{"class":379},[362,3023,406],{"class":471},[362,3025,475],{"class":379},[362,3027,2937],{"class":383},[362,3029,276],{"class":379},[362,3031,351],{"class":383},[362,3033,276],{"class":379},[362,3035,3036],{"class":383},"authorId",[362,3038,387],{"class":379},[362,3040,2968],{"class":471},[362,3042,475],{"class":379},[362,3044,2937],{"class":383},[362,3046,276],{"class":379},[362,3048,348],{"class":383},[362,3050,276],{"class":379},[362,3052,2560],{"class":383},[362,3054,543],{"class":379},[362,3056,489],{"class":383},[362,3058,507],{"class":379},[362,3060,3061],{"class":364,"line":780},[362,3062,2992],{"class":379},[362,3064,3065,3067,3069],{"class":364,"line":786},[362,3066,543],{"class":379},[362,3068,876],{"class":383},[362,3070,419],{"class":379},[362,3072,3073],{"class":364,"line":792},[362,3074,426],{"emptyLinePlaceholder":425},[362,3076,3077],{"class":364,"line":809},[362,3078,3079],{"class":368},"// Pass schema to TauriORM - relations are already applied to tables\n",[362,3081,3082,3084,3087,3089,3092,3095,3098,3100,3103],{"class":364,"line":835},[362,3083,1002],{"class":441},[362,3085,3086],{"class":383}," orm ",[362,3088,448],{"class":379},[362,3090,3091],{"class":379}," new",[362,3093,3094],{"class":451}," TauriORM",[362,3096,3097],{"class":383},"(db",[362,3099,387],{"class":379},[362,3101,3102],{"class":383}," schema)",[362,3104,419],{"class":379},[243,3106,3107],{},[284,3108,3109],{},"Benefits of v2:",[278,3111,3112,3115,3126,3136,3142,3148,3154],{},[281,3113,3114],{},"One place for all relations",[281,3116,3117,2586,3119,3121,3122,2586,3124],{},[258,3118,2585],{},[258,3120,2589],{}," instead of ",[258,3123,300],{},[258,3125,303],{},[281,3127,3128,3129,3132,3133,3135],{},"Many-without-one: define ",[258,3130,3131],{},"r.many.posts({ from, to })"," without needing ",[258,3134,271],{}," on the other table",[281,3137,3138,3139,3141],{},"Many-to-many via ",[258,3140,337],{},": direct relation without nesting through junction",[281,3143,3144,3147],{},[258,3145,3146],{},"optional: false"," on one relations: type-level required (T not T | null)",[281,3149,3150,3153],{},[258,3151,3152],{},"where: (alias) => Condition"," on many relations: predefined filters",[281,3155,3156,3157,3160],{},"Use ",[258,3158,3159],{},"defineRelationsPart"," to split large schemas",[243,3162,3163],{},[284,3164,3165,3166,475],{},"Many-to-many with ",[258,3167,337],{},[353,3169,3171],{"className":993,"code":3170,"language":995,"meta":358,"style":358},"defineRelations(schema, (r) => ({\n  posts: {\n    user: r.one.users({ from: r.posts.userId, to: r.users.id }),\n    postTags: r.many.postTags({ from: r.posts.id, to: r.postTags.postId }),\n    tags: r.many.tags({\n      from: through(r.posts.id, r.postTags.postId, postTags),\n      to: through(r.tags.id, r.postTags.tagId, postTags),\n    }),\n  },\n}));\n\n// Query: posts.include({ tags: true }) — direct, no nested postTags\n",[258,3172,3173,3193,3201,3259,3317,3338,3379,3417,3426,3430,3438,3442],{"__ignoreMap":358},[362,3174,3175,3177,3179,3181,3183,3185,3187,3189,3191],{"class":364,"line":365},[362,3176,333],{"class":451},[362,3178,2903],{"class":383},[362,3180,387],{"class":379},[362,3182,768],{"class":379},[362,3184,2910],{"class":759},[362,3186,489],{"class":379},[362,3188,678],{"class":441},[362,3190,768],{"class":383},[362,3192,771],{"class":379},[362,3194,3195,3197,3199],{"class":364,"line":372},[362,3196,944],{"class":471},[362,3198,475],{"class":379},[362,3200,465],{"class":379},[362,3202,3203,3206,3208,3210,3212,3214,3216,3218,3220,3222,3224,3226,3228,3230,3232,3234,3237,3239,3241,3243,3245,3247,3249,3251,3253,3255,3257],{"class":364,"line":422},[362,3204,3205],{"class":471},"    user",[362,3207,475],{"class":379},[362,3209,2937],{"class":383},[362,3211,276],{"class":379},[362,3213,271],{"class":383},[362,3215,276],{"class":379},[362,3217,348],{"class":451},[362,3219,454],{"class":383},[362,3221,1067],{"class":379},[362,3223,406],{"class":471},[362,3225,475],{"class":379},[362,3227,2937],{"class":383},[362,3229,276],{"class":379},[362,3231,351],{"class":383},[362,3233,276],{"class":379},[362,3235,3236],{"class":383},"userId",[362,3238,387],{"class":379},[362,3240,2968],{"class":471},[362,3242,475],{"class":379},[362,3244,2937],{"class":383},[362,3246,276],{"class":379},[362,3248,348],{"class":383},[362,3250,276],{"class":379},[362,3252,2560],{"class":383},[362,3254,543],{"class":379},[362,3256,489],{"class":383},[362,3258,507],{"class":379},[362,3260,3261,3263,3265,3267,3269,3271,3273,3276,3278,3280,3282,3284,3286,3288,3290,3292,3294,3296,3298,3300,3302,3304,3306,3308,3311,3313,3315],{"class":364,"line":429},[362,3262,2228],{"class":471},[362,3264,475],{"class":379},[362,3266,2937],{"class":383},[362,3268,276],{"class":379},[362,3270,275],{"class":383},[362,3272,276],{"class":379},[362,3274,3275],{"class":451},"postTags",[362,3277,454],{"class":383},[362,3279,1067],{"class":379},[362,3281,406],{"class":471},[362,3283,475],{"class":379},[362,3285,2937],{"class":383},[362,3287,276],{"class":379},[362,3289,351],{"class":383},[362,3291,276],{"class":379},[362,3293,484],{"class":383},[362,3295,387],{"class":379},[362,3297,2968],{"class":471},[362,3299,475],{"class":379},[362,3301,2937],{"class":383},[362,3303,276],{"class":379},[362,3305,3275],{"class":383},[362,3307,276],{"class":379},[362,3309,3310],{"class":383},"postId ",[362,3312,543],{"class":379},[362,3314,489],{"class":383},[362,3316,507],{"class":379},[362,3318,3319,3322,3324,3326,3328,3330,3332,3334,3336],{"class":364,"line":435},[362,3320,3321],{"class":471},"    tags",[362,3323,475],{"class":379},[362,3325,2937],{"class":383},[362,3327,276],{"class":379},[362,3329,275],{"class":383},[362,3331,276],{"class":379},[362,3333,1567],{"class":451},[362,3335,454],{"class":383},[362,3337,771],{"class":379},[362,3339,3340,3343,3345,3348,3351,3353,3355,3357,3359,3361,3363,3365,3367,3369,3372,3374,3377],{"class":364,"line":468},[362,3341,3342],{"class":471},"      from",[362,3344,475],{"class":379},[362,3346,3347],{"class":451}," through",[362,3349,3350],{"class":383},"(r",[362,3352,276],{"class":379},[362,3354,351],{"class":383},[362,3356,276],{"class":379},[362,3358,484],{"class":383},[362,3360,387],{"class":379},[362,3362,2937],{"class":383},[362,3364,276],{"class":379},[362,3366,3275],{"class":383},[362,3368,276],{"class":379},[362,3370,3371],{"class":383},"postId",[362,3373,387],{"class":379},[362,3375,3376],{"class":383}," postTags)",[362,3378,507],{"class":379},[362,3380,3381,3384,3386,3388,3390,3392,3394,3396,3398,3400,3402,3404,3406,3408,3411,3413,3415],{"class":364,"line":510},[362,3382,3383],{"class":471},"      to",[362,3385,475],{"class":379},[362,3387,3347],{"class":451},[362,3389,3350],{"class":383},[362,3391,276],{"class":379},[362,3393,1567],{"class":383},[362,3395,276],{"class":379},[362,3397,484],{"class":383},[362,3399,387],{"class":379},[362,3401,2937],{"class":383},[362,3403,276],{"class":379},[362,3405,3275],{"class":383},[362,3407,276],{"class":379},[362,3409,3410],{"class":383},"tagId",[362,3412,387],{"class":379},[362,3414,3376],{"class":383},[362,3416,507],{"class":379},[362,3418,3419,3422,3424],{"class":364,"line":540},[362,3420,3421],{"class":379},"    }",[362,3423,489],{"class":383},[362,3425,507],{"class":379},[362,3427,3428],{"class":364,"line":550},[362,3429,2992],{"class":379},[362,3431,3432,3434,3436],{"class":364,"line":555},[362,3433,543],{"class":379},[362,3435,876],{"class":383},[362,3437,419],{"class":379},[362,3439,3440],{"class":364,"line":581},[362,3441,426],{"emptyLinePlaceholder":425},[362,3443,3444],{"class":364,"line":614},[362,3445,3446],{"class":368},"// Query: posts.include({ tags: true }) — direct, no nested postTags\n",[243,3448,3449,3450,3452],{},"The v1 ",[258,3451,1338],{}," API remains fully supported for backward compatibility.",[250,3454,3456],{"id":3455},"_5-typing-relational-results","5. Typing Relational Results",[243,3458,3156,3459,3462,3463,3465],{},[258,3460,3461],{},"InferRelationalSelectModel"," to infer the result type of queries that use ",[258,3464,975],{},". This gives you full type safety and autocompletion for nested relation data.",[353,3467,3469],{"className":993,"code":3468,"language":995,"meta":358,"style":358},"import { InferSelectModel, InferRelationalSelectModel } from '@type32/tauri-sqlite-orm';\nimport { users, usersRelations, posts } from '$lib/db/schema';\n\nexport type User = InferSelectModel\u003Ctypeof users>;\n\nconst withPosts = { posts: true } as const;\nexport type UserWithPosts = InferRelationalSelectModel\u003C\n  typeof users,\n  typeof usersRelations,\n  typeof withPosts\n>;\n// UserWithPosts = User & { posts: Post[] }\n",[258,3470,3471,3497,3527,3531,3555,3559,3585,3601,3610,3618,3625,3629],{"__ignoreMap":358},[362,3472,3473,3475,3477,3480,3482,3485,3487,3489,3491,3493,3495],{"class":364,"line":365},[362,3474,376],{"class":375},[362,3476,380],{"class":379},[362,3478,3479],{"class":383}," InferSelectModel",[362,3481,387],{"class":379},[362,3483,3484],{"class":383}," InferRelationalSelectModel",[362,3486,403],{"class":379},[362,3488,406],{"class":375},[362,3490,409],{"class":379},[362,3492,413],{"class":412},[362,3494,416],{"class":379},[362,3496,419],{"class":379},[362,3498,3499,3501,3503,3505,3507,3510,3512,3514,3516,3518,3520,3523,3525],{"class":364,"line":372},[362,3500,376],{"class":375},[362,3502,380],{"class":379},[362,3504,681],{"class":383},[362,3506,387],{"class":379},[362,3508,3509],{"class":383}," usersRelations",[362,3511,387],{"class":379},[362,3513,1070],{"class":383},[362,3515,403],{"class":379},[362,3517,406],{"class":375},[362,3519,409],{"class":379},[362,3521,3522],{"class":412},"$lib/db/schema",[362,3524,416],{"class":379},[362,3526,419],{"class":379},[362,3528,3529],{"class":364,"line":422},[362,3530,426],{"emptyLinePlaceholder":425},[362,3532,3533,3535,3538,3542,3545,3547,3550,3552],{"class":364,"line":429},[362,3534,438],{"class":375},[362,3536,3537],{"class":441}," type",[362,3539,3541],{"class":3540},"sBMFI"," User",[362,3543,3544],{"class":379}," =",[362,3546,3479],{"class":3540},[362,3548,3549],{"class":379},"\u003Ctypeof",[362,3551,681],{"class":383},[362,3553,3554],{"class":379},">;\n",[362,3556,3557],{"class":364,"line":435},[362,3558,426],{"emptyLinePlaceholder":425},[362,3560,3561,3563,3566,3568,3570,3572,3574,3576,3578,3581,3583],{"class":364,"line":468},[362,3562,1002],{"class":441},[362,3564,3565],{"class":383}," withPosts ",[362,3567,448],{"class":379},[362,3569,380],{"class":379},[362,3571,1070],{"class":471},[362,3573,475],{"class":379},[362,3575,1076],{"class":1075},[362,3577,403],{"class":379},[362,3579,3580],{"class":375}," as",[362,3582,442],{"class":441},[362,3584,419],{"class":379},[362,3586,3587,3589,3591,3594,3596,3598],{"class":364,"line":510},[362,3588,438],{"class":375},[362,3590,3537],{"class":441},[362,3592,3593],{"class":3540}," UserWithPosts",[362,3595,3544],{"class":379},[362,3597,3484],{"class":3540},[362,3599,3600],{"class":379},"\u003C\n",[362,3602,3603,3606,3608],{"class":364,"line":540},[362,3604,3605],{"class":379},"  typeof",[362,3607,681],{"class":383},[362,3609,507],{"class":379},[362,3611,3612,3614,3616],{"class":364,"line":550},[362,3613,3605],{"class":379},[362,3615,3509],{"class":383},[362,3617,507],{"class":379},[362,3619,3620,3622],{"class":364,"line":555},[362,3621,3605],{"class":379},[362,3623,3624],{"class":383}," withPosts\n",[362,3626,3627],{"class":364,"line":581},[362,3628,3554],{"class":379},[362,3630,3631],{"class":364,"line":614},[362,3632,3633],{"class":368},"// UserWithPosts = User & { posts: Post[] }\n",[243,3635,3636,3637,3640],{},"For nested includes, pass a map of table name → relations as the fourth parameter. See ",[2353,3638,217],{"href":3639},"/6.advanced-topics/6.type-safety-and-inference#inferrelationalselectmodel"," for full details.",[250,3642,3644],{"id":3643},"_6-key-points","6. Key Points",[278,3646,3647,3653,3659,3665,3686],{},[281,3648,3649,3652],{},[284,3650,3651],{},"Primary Keys Required",": The ORM uses primary keys to properly group and deduplicate results when loading relations.",[281,3654,3655,3658],{},[284,3656,3657],{},"Junction Table",": For many-to-many relations, always create a separate junction table to store the relationships.",[281,3660,3661,3664],{},[284,3662,3663],{},"Bidirectional Relations",": You can define relations from both sides (e.g., students → courses AND courses → students), allowing you to query from either direction.",[281,3666,3667,3670,3671],{},[284,3668,3669],{},"Result Shape",":\n",[278,3672,3673,3678],{},[281,3674,3675,3677],{},[258,3676,271],{}," relations return a single object (or null if not found)",[281,3679,3680,272,3682,3685],{},[258,3681,275],{},[258,3683,3684],{},"manyToMany"," relations return an array (empty array if no related records)",[281,3687,3688,3691],{},[284,3689,3690],{},"Performance",": Relations use LEFT JOINs, so the main query will still return results even if there are no related records.",[3693,3694,3695],"style",{},"html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sfNiH, html code.shiki .sfNiH{--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}",{"title":358,"searchDepth":372,"depth":372,"links":3697},[3698,3701,3708,3713,3714,3715],{"id":252,"depth":372,"text":253,"children":3699},[3700],{"id":341,"depth":422,"text":342},{"id":965,"depth":372,"text":3702,"children":3703},"2. Querying with include",[3704,3706],{"id":983,"depth":422,"text":3705},"One-to-Many (many) Example",{"id":1156,"depth":422,"text":3707},"Many-to-One (one) Example",{"id":1324,"depth":372,"text":1325,"children":3709},[3710,3711,3712],{"id":1353,"depth":422,"text":1354},{"id":2175,"depth":422,"text":2176},{"id":2359,"depth":422,"text":2360},{"id":2578,"depth":372,"text":2579},{"id":3455,"depth":372,"text":3456},{"id":3643,"depth":372,"text":3644},"Relations in Tauri SQLite ORM.","md",null,{},{"title":193,"description":3716},"7BcoGb6ammd7Tmd-BzrSMV1xnIoe9pHhY1sOL5xw_PI",[3723,3725],{"title":184,"path":185,"stem":186,"description":3724,"children":-1},"Using Conditions & Operators in Tauri SQLite ORM.",{"title":197,"path":198,"stem":199,"description":3726,"children":-1},"Error handling, WHERE validation, and safety features",1773317304235]