How to create a model when the database table contains hyphens?
P粉007288593
P粉007288593 2023-08-31 14:08:40
0
1
553
<p>I have tables with hyphens in my database, for example "user-cars". I can't change the name to "user_cars". Is there a way to name the model "user_cars" but have it reference the "user-cars" table? I tried <code>@@map("user_cars")</code> but it didn't work. </p>
P粉007288593
P粉007288593

reply all(1)
P粉520545753

According to the documentation, you need to map the model to the underlying table name. You tried user_cars, but did you try user-cars? If your table name is user-cars, then you should map it to your model like this:

model UserCar {
  // Fields

  @@map("user-cars")
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template