I have a table "Category" and another "Subcategory". Then I have "Products" table.
Some of these products will be related directly to the "Subcategroy" table, but some of them will be related directly to "Category". What should be the tables structure in this case?
Use Association Mapping
This chapter explains mapping associations between objects.
Instead of working with foreign keys in your code, you will always work with references to objects instead and Doctrine will convert those references to foreign keys internally.
http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html