How can i use one sequence to auto increment several tables in squeryl (PostgreSQL)?

StackOverflow https://stackoverflow.com/questions/22591226

  •  19-06-2023
  •  | 
  •  

سؤال

I have follows

val s1 = autoIncremented("advert_id_seq")
on(car)(attributes => declare(attributes.id is (s1)))
on(danceInstructor)(attributes => declare(attributes.id is (s1)))

When i run my app a catch following exception

org.postgresql.util.PSQLException: ERROR: relation "advert_id_seq" already exists

As i realized, squeryl try to create sequence twice and gets error

هل كانت مفيدة؟

المحلول 2

Ruby on Rails has a polymorphic association, but scala active record don't have its. I made something like it's, and will push it in github repo.

نصائح أخرى

I'm guessing that your issue is with Schema generation, not with querying the database. If that's the case, then you probably just want to avoid having Squeryl create the tables directly. Squeryl's schema generation is purposefully basic. When you outgrow what it can do I think you're better off adopting some method that gives you greater control than a "read your model and generate stuff" tool can offer. Tools like Flyway or Liquibase are good for this.

If you don't want to adopt a new library you can also use Squeryl to output the schema to a file through one of the Schema.printDdl methods then remove the extraneous sequence before executing it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top