{"action":"created","issue":{"url":"https://api.github.com/repos/lotus/model/issues/155","labels_url":"https://api.github.com/repos/lotus/model/issues/155/labels{/name}","comments_url":"https://api.github.com/repos/lotus/model/issues/155/comments","events_url":"https://api.github.com/repos/lotus/model/issues/155/events","html_url":"https://github.com/lotus/model/issues/155","id":58703605,"number":155,"title":"Working with default values","user":{"login":"7even","id":351591,"avatar_url":"https://avatars.githubusercontent.com/u/351591?v=3","gravatar_id":"","url":"https://api.github.com/users/7even","html_url":"https://github.com/7even","followers_url":"https://api.github.com/users/7even/followers","following_url":"https://api.github.com/users/7even/following{/other_user}","gists_url":"https://api.github.com/users/7even/gists{/gist_id}","starred_url":"https://api.github.com/users/7even/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/7even/subscriptions","organizations_url":"https://api.github.com/users/7even/orgs","repos_url":"https://api.github.com/users/7even/repos","events_url":"https://api.github.com/users/7even/events{/privacy}","received_events_url":"https://api.github.com/users/7even/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-24T07:37:05Z","updated_at":"2015-02-24T08:28:58Z","closed_at":null,"body":"Currently `lotus-model` doesn't respect default values in the database:\r\n\r\n``` sql\r\nCREATE TABLE deployments (\r\n    id integer NOT NULL,\r\n    project_id integer NOT NULL,\r\n    environment character varying NOT NULL,\r\n    branch character varying NOT NULL,\r\n    deployed_at timestamp with time zone DEFAULT now() NOT NULL\r\n);\r\n```\r\n\r\n``` ruby\r\nclass Deployment\r\n  include Lotus::Entity\r\n  attributes :id, :project_id, :environment, :branch, :deployed_at\r\n  \r\n  attr_accessor :project\r\nend\r\n\r\ndeployment = Deployment.new(project_id: 1, environment: 'production', branch: 'master')\r\nDeploymentRepository.persist(deployment)\r\n# Sequel::NotNullConstraintViolation: PG::NotNullViolation: ERROR:  null value in column \"deployed_at\" violates not-null constraint\r\n# DETAIL:  Failing row contains (4, 1, production, master, null).\r\n```\r\n\r\nSeems like the empty `deployed_at` value is being written to the database. I see 2 possible ways to solve this issue: to read the default value into the entity upon it's creation (but I believe it breaks incapsulation and is not very helpful with a default value of `NOW()`), or to save only attributes that were changed."},"comment":{"url":"https://api.github.com/repos/lotus/model/issues/comments/75716911","html_url":"https://github.com/lotus/model/issues/155#issuecomment-75716911","issue_url":"https://api.github.com/repos/lotus/model/issues/155","id":75716911,"user":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"created_at":"2015-02-24T08:28:58Z","updated_at":"2015-02-24T08:28:58Z","body":"@7even Can you please also paste here the mapping for that entity?"}}