Hi,
I have a database setup like this:
Table A
ID
Table B
ID
A_ID - NOT NULL
Table C
ID
A_ID - NOT NULL
B_ID - DEFAULT NULL
A has many B
B belongs to A
C belongs to A
C belongs to B
B has one C
the record of C could be missing completely in some cases.
And now the problem:
Ik want to check before i save a new record of C(with A_ID and B_ID both set) that A_ID in Table B is the same as A_ID in Table C. How do i create a validator for this? And i want to check if another record of C already is connected to B because there can only be one relation between C and B.
edit:
this works
public function myValidator($attribute,$params)
{
if( $this->A_ID != $this->B->A_ID)
{
$this->addError($attribute, 'id\'s not the same');
}
}
but is this ok? because i can use any attribute i want and it always checks the same thing.
Thanks!