Problems with relations

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
Khaoz
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 18.04.2009, 21:01

Problems with relations

Post by Khaoz »

I have the following schema:

Code: Select all

contas
id
data
tipo_conta

despesas
despesas_conta_id // unique filed in this table

itens_despesas
despesa_id
custo
valor
My despesas dataset points to contas (one-to-one) with master field set to id
My itens_despesas points to despesas (one-to-many) with master field set to despesas_contas_id

When i try to post "contas" dataset my despesas dataset are canceled without any reason, error message...

Using or note cachedupdates, transactions ...

Zeos seems to not like to work with releations where de child tables has only one field because in other places i can use the same type of relation without any problems.

Example:

Code: Select all

contas
id
data

pagar
pagar_conta_id
value
My pagar dataset has two fields and points to contas (one-to-one) with master field set to id and zeos do not complain.

how to solve this ?
Khaoz
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 18.04.2009, 21:01

Post by Khaoz »

Here my contas, despesas and detalhamento_despesas schema:

Code: Select all

CREATE TABLE public.contas (
                id INTEGER NOT NULL DEFAULT nextval('public.contas_id_seq'),
                funcionario_id INTEGER NOT NULL,
                veiculo_id INTEGER NOT NULL,
                centro_resultado_id INTEGER NOT NULL,
                tipo_conta VARCHAR(20) NOT NULL,
                data DATE NOT NULL,
                valor NUMERIC(7,2) DEFAULT 0.00 NOT NULL,
                descricao VARCHAR(255) DEFAULT 0.00 NOT NULL,
                observacoes VARCHAR(10485760),
                CONSTRAINT contas_pkey PRIMARY KEY (id)
);

CREATE TABLE public.despesas (
                conta_ptr_id INTEGER NOT NULL,
                CONSTRAINT despesas_pkey PRIMARY KEY (conta_ptr_id)
);

CREATE TABLE public.detalhamento_despesas (
                id INTEGER NOT NULL DEFAULT nextval('public.detalhamento_despesas_id_seq'),
                despesa_id INTEGER NOT NULL,
                custo_id INTEGER NOT NULL,
                quantidade NUMERIC(16,2) DEFAULT 0.00 NOT NULL,
                total NUMERIC(16,2) DEFAULT 0.00 NOT NULL,
                valor_unitario NUMERIC(16,2) DEFAULT 0.00 NOT NULL,
                CONSTRAINT detalhamento_despesas_pkey PRIMARY KEY (id)
);
despesas -> contas relation:

Code: Select all

ALTER TABLE public.despesas ADD CONSTRAINT despesas_conta_ptr_id_fkey
FOREIGN KEY (conta_ptr_id)
REFERENCES public.contas (id)
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
detalhamento_despesas -> despesas relation:

Code: Select all

ALTER TABLE public.detalhamento_despesas ADD CONSTRAINT detalhamento_despesas_despesa_id_fkey
FOREIGN KEY (despesa_id)
REFERENCES public.despesas (conta_ptr_id)
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
Khaoz
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 18.04.2009, 21:01

Post by Khaoz »

Seems a problem with how i setup my master/detail relation.

How to do the right master/details relation setup with zeos ?

1) using the datasource property in detail query
2) using the mastersource and masterfields properties in detail query
3) using the mastersource, masterfields, linkedfields properties in detail query
4) using the mastersource, masterfields, indexfieldnames properties in detail query
Post Reply