Example #1
0
	USER_C_ID      = USER.KEY("ID")
	USER_C_VERSION = USER.VERSION("VERSION")
	// Audit
	USER_C_CREATION          = USER.COLUMN("CREATION")
	USER_C_MODIFICATION      = USER.COLUMN("MODIFICATION")
	USER_C_USER_CREATION     = USER.COLUMN("USER_CREATION").As("UserCreationId")
	USER_C_USER_MODIFICATION = USER.COLUMN("USER_MODIFICATION").As("UserModificationId")
	// Atributos
	USER_C_NAME     = USER.COLUMN("NAME")
	USER_C_USERNAME = USER.COLUMN("USERNAME")
	USER_C_PASSWORD = USER.COLUMN("PASSWORD")
	//FK's
	// many to many
	USER_A_BOARDS = db.NewM2MAssociation(
		"boards",
		db.ASSOCIATE(USER_C_ID).WITH(BOARD_USER_C_USERS_ID),
		db.ASSOCIATE(BOARD_USER_C_BOARDS_ID).WITH(BOARD_C_ID),
	)

	USER_A_ROLES = USER.
			ASSOCIATE(USER_C_ID).TO(ROLE_C_USER_ID).
			As("Roles")
	USER_A_TASKS = USER.
			ASSOCIATE(USER_C_ID).TO(TASK_C_USER_ID).
			As("Tasks")
	USER_A_USER_CREATION     = USER.ASSOCIATE(USER_C_USER_CREATION).TO(USER_C_ID).As("UserCreation")
	USER_A_USER_MODIFICATION = USER.ASSOCIATE(USER_C_USER_MODIFICATION).TO(USER_C_ID).As("UserModification")
)

func init() {
	USER.PreInsertTrigger = func(ins *db.Insert) {
Example #2
0
	BOARD_C_NAME        = BOARD.COLUMN("NAME")
	BOARD_C_DESCRIPTION = BOARD.COLUMN("DESCRIPTION")
	//FK's
	BOARD_A_LANES = BOARD.
			ASSOCIATE(BOARD_C_ID).TO(LANE_C_BOARD_ID).
			As("Lanes")

	// intermediary table
	BOARD_USER             = db.TABLE("USERS").As("Users")
	BOARD_USER_C_USERS_ID  = BOARD_USER.KEY("USER").As("Users")
	BOARD_USER_C_BOARDS_ID = BOARD_USER.KEY("BOARD").As("Boards")

	// many to many
	BOARD_A_USERS = db.NewM2MAssociation(
		"users",
		db.ASSOCIATE(BOARD_C_ID).WITH(BOARD_USER_C_BOARDS_ID),
		db.ASSOCIATE(BOARD_USER_C_USERS_ID).WITH(USER_C_ID),
	)

	BOARD_A_USER_CREATION     = BOARD.ASSOCIATE(BOARD_C_USER_CREATION).TO(USER_C_ID).As("UserCreation")
	BOARD_A_USER_MODIFICATION = BOARD.ASSOCIATE(BOARD_C_USER_MODIFICATION).TO(USER_C_ID).As("UserModification")
)

func init() {
	BOARD.PreInsertTrigger = func(ins *db.Insert) {
		ins.Set(BOARD_C_VERSION, 1)
		ins.Set(BOARD_C_CREATION, NOW())
		uid, ok := ins.GetDb().GetAttribute(entity.ATTR_USERID)
		if ok {
			ins.Set(BOARD_C_USER_CREATION, uid.(int64))
		}