【问题标题】:Neo4J gem datetime datatypeNeo4J gem 日期时间数据类型
【发布时间】:2014-11-22 09:19:01
【问题描述】:

我正在使用来自

的代码组合

http://railscasts.com/episodes/360-facebook-authentication?view=asciicast

oauth 部分并尝试将其与 neo4J 集成

https://github.com/neo4jrb/neo4j

据我所知,这个 gem 替换了许多活动记录片段,包括数据类型。

我正在尝试替换此代码块。他们将oauth_expires_at 设置为我不相信neo4j gem 具有的日期时间数据类型(我假设我不能使用日期类型,因为在这种情况下活动记录被neo4j 替换)。有什么办法可以解决这个问题?

  def self.from_omniauth(auth)
    where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.name = auth.info.name
      user.oauth_token = auth.credentials.token
      user.oauth_expires_at = Time.at(auth.credentials.expires_at)
      user.save!
    end
  end

【问题讨论】:

    标签: ruby-on-rails ruby neo4j facebook-oauth neo4j.rb


    【解决方案1】:

    gem 确实支持日期时间!为您的模型添加适当的属性。

    class User
      include Neo4j::ActiveNode
      property :provider
      property :uid
      property :name
      property :oauth_token
      property :auth_expries_at, type: DateTime
    end
    

    【讨论】:

    • 谢谢克里斯。是否将 DateTime 添加到 neo4J 中?我是否正确假设 neo4j 数据类型会覆盖旧的 AR 数据类型?我还试图了解是否自动创建了时间戳(created_at、updated_at)
    • 不是。我们使用 active_attr 来提供属性的类型转换,你可以看看它支持什么。保存时,您的 Rails 属性将转换为与 Neo4j 兼容的数据类型;当您加载时,它们会转换回您所期望的。 Time 是个例外,它存在于 gem 中,但实际上会给你 DateTime。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-20
    • 2011-09-24
    • 2022-01-01
    • 1970-01-01
    • 2010-10-05
    相关资源
    最近更新 更多