Still working on models

It's a slow progress but it's heading towards an end. Still need to
overwork some behaviors but sql generation works fine so far.