Yes, it is possible. If you’re having Squeryl generate the database schema for you, use the is autoIncremented
column attribute. See the documentation for more info. Either way Squeryl should retrieve the db generated value and update your model object when the row is inserted.
is it possible to using more than one autoincremented field with squeryl? database is postgresql.
--
You received this message because you are subscribed to the Google Groups "Squeryl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to squeryl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
CREATE TABLE orders ( id BIGSERIAL PRIMARY KEY, order_type_id INT REFERENCES order_types (id), date_of_order DATE, created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL);
CREATE TABLE employment_orders ( position_id INT, contract_type_id INT, contract_number BIGINT UNIQUE NOT NULL, employee_id BIGINT, salary NUMERIC(14, 2), calendar_type_id SMALLINT, trial_period_start DATE, trial_period_end DATE, start_date DATE, end_date DATE, close_date DATE) INHERITS (orders);
case class EmploymentOrder( id: Long, order_type_id: Int, date_of_order: Date, position_id: Int, contract_type_id: Int, contract_number: Long, employee_id: Long, salary: BigDecimal, calendar_type_id: Int, trial_period_start: Option[Date], trial_period_end: Option[Date], start_date: Date, end_date: Option[Date], close_date: Option[Date], override var created_at: TimeStamp, override var updated_at: TimeStamp ) extends Entity[Long]
object Database extends Schema {
...
...
val employmentOrderTable: Table[EmploymentOrder] = table[EmploymentOrder]("employment_orders")
on(employmentOrderTable) ( employmentOrder => declare ( employmentOrder.id is (autoIncremented("orders_id_seq")), employmentOrder.contract_number is (autoIncremented("employment_orders_contract_number_seq")) ))...
...
}
libraryDependencies ++= Seq( jdbc, cache, "org.squeryl" %% "squeryl" % "0.9.5-6", "postgresql" % "postgresql" % "9.2-1002.jdbc4", "org.webjars" %% "webjars-play" % "2.2.1", "org.webjars" % "bootstrap" % "3.1.1-2",
...other dependencies.
)
// Validate that autoIncremented is not used on other fields than KeyedEntity[A].id : // since it is not yet unsupported : for(ca <- colAss) ca match { case cga:CompositeKeyAttributeAssignment => {} case caa:ColumnAttributeAssignment => { for(ca <- caa.columnAttributes if ca.isInstanceOf[AutoIncremented] && !(caa.left.isIdFieldOfKeyedEntity)) org.squeryl.internals.Utils.throwError("Field " + caa.left.nameOfProperty + " of table " + table.name + " is declared as autoIncremented, auto increment is currently only supported on KeyedEntity[A].id") } case dva:Any => {} }
--