Continued work.

- Fixed foreign key retrieval (many-to-one and one-to-many);
- Tests;
- Some refactoring.