English 中文(简体)
多日期采集器的铁路数据设计
原标题:Rails data design for multiple date picker

我有一个任用模式,其可用日期可包括多个日期(例如,见Jan 1,5,6和7)。

我的问题非常基本:我如何为每次活动储存可用日期?

我可以认为的是一张可加利用的表格。 两个栏的日期:活动日期和日期。 每次活动都有多个渠道,每个行各有一天。 质疑整个议事桌,以确保我们了解事件的所有日期,似乎是麻烦的。 A Hash{event =>{date1,日期2,日期3 更快,但我不知道如何使用主动记录来执行。

谢谢。

最佳回答

仅仅利用现有时间使用单独模式可能不是一个坏的想法,但如果你决定采用散列路线,你可以使用序列号的关键词这样做。 你们必须告诉大家,要把变数编成序号,然后,只要你能够进入该地,就会自动进行序列化和脱硫化。

Saving arrays, hashes, and other non-mappable objects in text columns

活性记录可在使用YAML的正文栏中标明任何物体。 为此,你必须具体指出这一点,要求采用序列方法。 这使得能够在不做任何额外工作的情况下储存阵列、轮.和其他不可使用物体。

class User < ActiveRecord::Base
  serialize :preferences
end

user = User.create(:preferences => { "background" => "black", "display" => large })
User.find(user.id).preferences # => { "background" => "black", "display" => large }

如果一个序列化物体被检索为不属于等级的阶层的后代,那么,你还可以将一个等级选择作为第二参数提出例外。

class User < ActiveRecord::Base
  serialize :preferences, Hash
end

user = User.create(:preferences => %w( one two three ))
User.find(user.id).preferences    # raises SerializationTypeMismatch

When you specify a class option, the default value for that attribute will be a new instance of that class.

class User < ActiveRecord::Base
  serialize :preferences, OpenStruct
end

user = User.new
user.preferences.theme_color = "red"

From rubyonrails.org

从设计的角度来看,如果你认为你会给现有的时间目标增加任何数据,那么你就应当提出自己的模式。 否则,序列化散射似乎被罚款。

问题回答

我没有看到你提到的单独表格存在问题,我会这样做。 更方便地延长你在时机成熟时将不胜感激。





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签