Fixed database relationship functionality