Symfony 3 2实体一种形式(Symfony 3 2 entities one form)
我试图弄清楚如何在一个表单中使用两个实体。 我有用户实体和配置文件实体。 我创建了一个RegisterType类,该类包含用户实体的字段,之后我在用户和配置文件之间添加了一对一映射。 现在在我的RegisterType中,我想要有与ProfileEntity相关的字段,如电话,地址。 我试着创建一个ProfileType的实例,它是Profile实体的表单生成器类,然后像这样在RegisterType中创建一个实例
->add('profile', ProfileType::class, [])
在表单提交后我的registerAction方法中,我添加了以下行来添加关系并保存与Profile实体相关的字段的数据。
$user->setProfile($form['profile']->getData()->setUser($user));
我这样做,因为如果我不会有上面的行,它不会保存用户和配置文件之间的映射。 我应该使用什么方法?
I'm trying to figure it out how to use two entities in a single form. I have User entity and Profile entity. I've created a RegisterType class that holds the fields for the User Entity and after that i added a one-to-one mapping between User and Profile. Now in my RegisterType i would like to have fields related to the ProfileEntity like phone, address. I tried creating an instance of ProfileType which is the form builder class for the Profile entity and then create an instance of it inside the RegisterType like this
->add('profile', ProfileType::class, [])
In my registerAction method after form submit i added the following line to add the relation and save the data for the fields related to the Profile entity.
$user->setProfile($form['profile']->getData()->setUser($user));
I did it like that because if i wouldn't have the above line it wouldn't save the mapping between user and profile. What is approach that i should use ?
原文:https://stackoverflow.com/questions/42448684
最满意答案
好像你想要将整列转换为Timedelta
df['end_date'] = df['start_date'] + df.total_waiting_days.apply(lambda x :pd.Timedelta(x, unit='D'))
Seems like you want to convert whole column to Timedelta
df['end_date'] = df['start_date'] + df.total_waiting_days.apply(lambda x :pd.Timedelta(x, unit='D'))
相关问答
更多-
你可以尝试这样: df.set_index(pd.to_datetime(df.date + ' ' + df.time), inplace=True) 如果您想在之后删除'date'和'time'列,您可以这样做: df.drop(['date','time'], axis=1, inplace=True) You can try like so: df.set_index(pd.to_datetime(df.date + ' ' + df.time), inplace=True) If you w ...
-
import org.apache.spark.sql.types.DateType import org.apache.spark.sql.functions._ import org.joda.time.DateTime import org.joda.time.format.DateTimeFormat val d = DateTimeFormat.forPattern("yyyy-mm-dd'T'kk:mm:ssZ") val dtFunc: (String => Date) = (arg1: S ...
-
创建一个包含自pandas中上一个事件以来的时间的新列(Create a new column containing time since last event in pandas)[2022-12-15]
如果您重置索引以便ID和日期是列(只是为了更容易引用它们 - df.index.get_level_values("date")有点笨拙)并确保df [“date”]是真实的datetime列而不是字符串,我认为这很简单: df["time_1"] = df["date"] - df["date"].where(df["event_1"]).groupby(df["ID"]).ffill() df["time_2"] = df["date"] - df["date"].where(df["event_2"] ... -
如何根据Pandas条件的现有列创建两列?(How create two columns based on existing column with conditions in Pandas?)[2023-06-02]
首先用布尔掩码和mask替换NaN s的fillna ,然后用bfill用于向后填充ffill用于向前填充,最后用fillna替换NaN : #only years are numeric mask = df['Date'].str.isnumeric() #alternative mask -check length of string #mask = df['Date'].str.len() == 4 #not numeric return NaNs, so test non NaNs #mask = ... -
熊猫:通过组合现有列创建新的日期时间列(pandas: create a new date time column by combining existing columns)[2023-07-15]
好像你想要将整列转换为Timedelta df['end_date'] = df['start_date'] + df.total_waiting_days.apply(lambda x :pd.Timedelta(x, unit='D')) Seems like you want to convert whole column to Timedelta df['end_date'] = df['start_date'] + df.total_waiting_days.apply(lambda x :pd ... -
如何通过加入pandas中的现有列来创建新列(how to make a new column by joining to existing column in pandas)[2023-05-10]
假设列是字符串,添加它们并使用pd.to_datetime df.assign(DateTime=pd.to_datetime(df.Date + ' ' + df.Time)) Index Date Time DateTime 0 0 26-10-2017 06:00:00 2017-10-26 06:00:00 1 1 26-10-2017 06:15:00 2017-10-26 06:15:00 2 2 26 ... -
定义varchar变量@time的大小。 默认值是1。 您还需要将第二个子字符串更改为3,2 。 DECLARE @date DATETIME DECLARE @time VARCHAR(4) SET @date = '2007-10-06 00:00:00.000' SET @time = '1125' SELECT TOP 1 @date + ( SUBSTRING(@time , 1 , 2) + ':' + SUBSTRING(@time , 3 , 2) + ...
-
重建您的数据: dat <- read.table(text=" date time numbers 01-02-2010 14:57 5 01-02-2010 23:23 7 02-02-2010 05:05 3 02-02-2010 10:23 11", header=TRUE) 现在使用as.POSIXct()和paste()将日期和时间组合成一个POSIX日期。 您需要使用?strptime定义的符号来指定格式。 另请参阅?DateTimeClasses以获取更多 ...
-
如何在新列中将纪元时间转换为日期和时间格式?(How to convert epoch time to date and time format in new columns?)[2022-10-01]
Oracle DATE类型包含日期和时间元素,精度低至第二个。 没有理由将相关的日期和时间分成两列; 有一个列并提取适当的值仅供显示: create table new_table (id, unixtime, realtime) as select id, unixtime, date '1970-01-01' + unixtime/86400 from orig_table; select id, unixtime, to_char(realtime, 'DD Mon YYYY HH24:MI:S ... -
你可以在to_datetime使用strftime : df['date'] = pd.to_datetime(df.FltDate.dt.strftime('%Y-%m-%d ') + df.ESTAD2.dt.strftime('%H:%M:%S')) print (df) Airport FltDate Carrier ESTAD2 date 0 EDI 2017-06-1 ...