diff --git a/src/Jasny/DB/Generator.php b/src/Jasny/DB/Generator.php
index <HASH>..<HASH> 100644
--- a/src/Jasny/DB/Generator.php
+++ b/src/Jasny/DB/Generator.php
@@ -226,13 +226,24 @@ $properties
     /**
      * Cast all properties to a type based on the field types.
      * 
-     * @return Record \$this
+     * @return $classname \$this
      */
     public function cast()
     {
 $cast
         return \$this;
     }
+                
+    /**
+     * Set the table gateway.
+     * @ignore
+     * 
+     * @param {$classname}Table \$table
+     */
+    public function _setDBTable(\$table)
+    {
+        if (!isset(\$this->_dbtable)) \$this->_dbtable = \$table;
+    }
 }
 
 PHP;
diff --git a/src/Jasny/DB/Record.php b/src/Jasny/DB/Record.php
index <HASH>..<HASH> 100644
--- a/src/Jasny/DB/Record.php
+++ b/src/Jasny/DB/Record.php
@@ -139,7 +139,10 @@ class Record
      */
     public function _setDBTable($table)
     {
-        if (!isset($this->_dbtable)) $this->_dbtable = $table;
+        if (!isset($this->_dbtable)) {
+            $this->_dbtable = $table;
+            $this->cast();
+         }
     }
     
     /**
Cast directly instantiated Records when setting the table gateway.