require 'sequel'
require_relative './member'

module CartoDB
  module Visualization

    class ExternalSource < Sequel::Model
      many_to_one :visualization

      def validate
        validates_presence :visualization_id
        validates_presence :import_url
        # TODO: retrieve geometry_types
        #validates_presence :geometry_types
        validates_presence :rows_counted
        validates_presence :size
      end

      def initialize(visualization_id, import_url, geometry_types, rows_counted, size, username = nil)
        super({ visualization_id: visualization_id, import_url: import_url, geometry_types: geometry_types, rows_counted: rows_counted, size: size, username: username })
      end

      def importable_by?(user)
        user.present? && visualization.user_id == user.id
      end

      def visualization
        @visualization ||= CartoDB::Visualization::Member.new(id: visualization_id).fetch
      end

    end
  end
end

require 'sequel'
require_relative './member'

module CartoDB
  module Visualization

    class ExternalSource < Sequel::Model

      def validate
        validates_presence :visualization_id
        validates_presence :import_url
        # TODO: retrieve geometry_types
        #validates_presence :geometry_types
        validates_presence :rows_counted
        validates_presence :size
      end

      def initialize(visualization_id, import_url, geometry_types, rows_counted, size, username = nil)
        super({ visualization_id: visualization_id, import_url: import_url, geometry_types: geometry_types, rows_counted: rows_counted, size: size, username: username })
      end

      def importable_by?(user)
        user.present? && visualization.user_id == user.id
      end

      def visualization
        @visualization ||= CartoDB::Visualization::Member.new(id: visualization_id).fetch
      end

    end
  end
end

Remove fake Sequel model association
Remove fake Sequel model association

The visualization is retrieved through a class method defined below,
and trying to use the association in the sequel model can yield
errors:

/var/lib/gems/2.5.0/gems/activesupport-4.2.11.3/lib/active_support/inflector/methods.rb:263:in `const_get': uninitialized constant CartoDB::Visualization::Visualization (this happened when attempting to $
ind the associated class for #<Sequel::Model::Associations::ManyToOneAssociationReflection CartoDB::Visualization::ExternalSource.many_to_one :visualization>) (NameError)
