Hello. I have two classes: User and Competition. I need to make a relationship between the two, as below:
public class User extends Model{
}
@Table(value = "competencias")
@BelongsTo(foreignKeyName = "user_id", parent = User.class)
public class Competencia extends Model{
}
CREATE TABLE users(
id integer NOT NULL DEFAULT nextval('operadores_id_seq'::regclass),
nome character varying(25) NOT NULL,
nome_completo character varying(60) NOT NULL,
email character varying(100) NOT NULL,
senha character varying(120) NOT NULL,
nivel integer NOT NULL DEFAULT 4,
ativo boolean,
created_at date DEFAULT now()
)
CREATE TABLE competencias(
id INTEGER NOT NULL DEFAULT NEXTVAL('competencias_id_seq'::regclass),
mes CHARACTER(2) NOT NULL,
ano CHARACTER(4) NOT NULL,
created_at DATE NOT NULL DEFAULT now(),
user_id INTEGER NOT NULL,
ativo BOOLEAN,
CONSTRAINT fk_competencia_operador FOREIGN KEY (user_id)
REFERENCES public.users (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE NO ACTION
)
When commanding the relationship recording in the Competencies table, I get the following error:
competencia.add(user);
Exception in thread "AWT-EventQueue-0" org.javalite.activejdbc.associations.NotAssociatedException: No association from table 'competencias' to table 'users'