Eloquent saveMany - eloquent

Why can't I retrieve my associated collection after using saveMany? When I do the following below, the data saves properly but my association is empty.
$event = new Event();
$signup = new Signup();
$signup->name = "James";
$signup2 = new Signup();
$signup2->name = "Joe";
$signups = array($signup, $signup2);
$event->signups()->saveMany($signups);
$event->signups // empty collection
Thanks

Related

How do I populate a LiteDB database if some of my values are null

I am populating a dataGridView from an incomplete excel spreadsheet and generating the LiteDB from the dataGridView. Before the recent update, I wasn't having any issues. Now I am getting the error 'Objects cannot be cast from DBNull to other types'. I can work around this by including dummy values in the original spreadsheet. But ultimately we need to see what information we're missing. How can I accomplish this?
public void CreateDatabase()
{
using (var db = new LiteDatabase(#"C:\Users\BThatcher\Documents\_Personal\Revit\MDL-Sheets\SheetDatabase04.db")) //< ----------------
{
var sheets = db.GetCollection<Sheet>("sheets");
foreach (DataGridViewRow row in dataGridView2.Rows)
{
var sheet = new Sheet
{
SheetSequence = Convert.ToInt32(row.Cells[0].Value),
SheetNumber = row.Cells[1].Value.ToString(),
SheetName = row.Cells[2].Value.ToString(),
AreaNumber = Convert.ToInt32(row.Cells[3].Value),
AreaName = row.Cells[4].Value.ToString(),
SheetDiscipline = row.Cells[5].Value.ToString(),
DisciplineSort = Convert.ToInt32(row.Cells[6].Value),
SheetSort = Convert.ToInt32(row.Cells[7].Value),
ModelName = row.Cells[8].Value.ToString(),
AppearsInSheetlist = row.Cells[9].Value.ToString(),
DesignedBy = row.Cells[10].Value.ToString(),
DrawnBy = row.Cells[11].Value.ToString(),
CheckedBy = row.Cells[12].Value.ToString(),
ApprovedBy = row.Cells[13].Value.ToString(),
SheetTotal = Convert.ToInt32(row.Cells[14].Value),
DesignSoftware = row.Cells[15].Value.ToString(),
HasPdf = row.Cells[16].Value.ToString(),
PdfPath = row.Cells[17].Value.ToString(),
};
sheets.Insert(sheet);
this.Close();
}
}
}
This error are not from LiteDB (there is no DBNull in LiteDB). It's possible this DBNull are getting from row.Cells[n].Value when you try to convert.
LiteDB support nulls and nullable values (like int?).

PSI update resource custom field with lookup table (Project Server)

Can someone show me a code to update a enterprise resource custom field with lookup table ? Already ran the internet looking for some sample code but did not succeed.
You can create and update a custom field with a lookup table using the below code . But we can not update or delete builtin custom fields
var projContext = new ProjectContext(projectServerUrl);
CustomFieldCollection CustomField = projContext.CustomFields;
EntityTypes Entitytype = projContext.EntityTypes;
LookupTableCollection lookupTables = projContext.LookupTables;
projContext.Load(CustomField);
projContext.Load(Entitytype);
projContext.Load(lookupTables);
projContext.ExecuteQuery();
CustomFieldCreationInformation NewfieldInfo = new CustomFieldCreationInformation();
NewfieldInfo.Id = new Guid();
NewfieldInfo.Name = "The Name";
NewfieldInfo.Description = "The Description";
NewfieldInfo.IsWorkflowControlled = true;
NewfieldInfo.IsRequired = true;
NewfieldInfo.IsEditableInVisibility = false;
NewfieldInfo.IsMultilineText = false;
LookupTable lookuptable = lookupTables.ToList().Find(x => x.Name == "LookupTableName");
projContext.Load(lookuptable);
projContext.ExecuteQuery();
NewfieldInfo.LookupTable = lookuptable;
NewfieldInfo.EntityType = Entitytype.ProjectEntity;
NewfieldInfo.FieldType = CustomFieldType.TEXT;
projContext.CustomFields.Add(NewfieldInfo);
projContext.CustomFields.Update();
projContext.ExecuteQuery();

Laravel 5 Form request and user register

The problem is, you need to simultaneously register the user and to enter into another table with its data forms and assign the ID
i tried
$data = Request::all();
$user = new App\User();
$user->username = $data['name'];
$user->email = $data['email'];
$user->password = bcrypt($data['password']);
$user->save();
how to immediately get a new user ID?
that would record other data such as
$question = new App\Question();
$question->name_q = $data['name_q'];
$question->body_q = $data['body_q'];
$question->user_id = ?
You should have relationship defined for that so that you can easily insert data without creating objects of two different tables. Lets first look at your case and then I will show you how to do it a better way.
$data = Request::all();
$user = new App\User();
$user->username = $data['name'];
$user->email = $data['email'];
$user->password = bcrypt($data['password']);
$user->save();
$question = new App\Question();
$question->name_q = $data['name_q'];
$question->body_q = $data['body_q'];
$question->user_id = $user->id;
$question->save();
and we are done. But in this case you have to create objects of two different tables and write everything that is ok as of now but what happens when you have to insert data into many many tables at a go. Lets see that:
Define a relationship first which you already have, lets see what we should have in the model :
//User model should have a questions function
public function questions()
{
return $this->hasMany('App\Question');
}
//Question model should have a user model
public function user()
{
return $this->belongsTo('App\User');
}
and now what we will do is
$user = new App\User();
$user->username = $data['name'];
$user->email = $data['email'];
$user->password = bcrypt($data['password']);
$user->save();
$user->questions()->create([
'field' => $somevariable,
'field' => $someothervariable
]);
//here questions is the function name in User model

how to set form element value in zend framework for editing

I am using zend framework. I have done user registration and login but i can't do update user information because i don't know how to show form element value in update form.Please tell me any solution.
$editClientForm = new Form_AddNewClientForm();
$editClientForm->setAction($this->view->baseUrl().'/client/edit');
//fetch client data from your database through model
$clientInfo = $mdlClient->fetchClientDetails($id);
//populate the data to form
$editClientForm->populate($clientInfo);
$this->view->editClientForm = $editClientForm;
Update
After taking suggestion of #php-dev:
$editClientForm = new Form_AddNewClientForm();
$editClientForm->setAction($this->view->baseUrl().'/client/edit');
//fetch client data from your database through model
$mdlClient = new Model_Client();
$clientInfo = $mdlClient->fetchClientDetails($id);
//populate the data to form
$editClientForm->populate($clientInfo);
$this->view->editClientForm = $editClientForm;
Inside your model:
public function fetchClientDetails($id)
{
$row = $this->_db->fetchRow("SELECT * from tablename where id = $id");
return $row;
}

Despite loading new data from code, report displays original data

as below i have code to display data,
it works very fine, while data available..
but it shows same data, if query doeent return any rows, it shows last loaded data,
even if query returns other data eventhough it shows last loaded data..
please help me out...
ReportDocument rptdoc = new ReportDocument();
Ds2 = new DataSet();
Ds2 = ClsPos.GetRejectedByPosition(int.Parse(Request.QueryString.Get("ID")));
string ReportName = Server.MapPath("RejectedCandidate.rpt");
rptdoc.Load(ReportName);
// Position Name
ParameterFields Parameters = new ParameterFields();
ParameterField idget = new ParameterField();
idget.Name = "PositionName";
ParameterDiscreteValue values = new ParameterDiscreteValue();
values.Value = Request.QueryString.Get("PositionName");
idget.CurrentValues.Add(values);
Parameters.Add(idget);
CRViewer1.ParameterFieldInfo = Parameters;
rptdoc.SetDataSource(Ds2.Tables["GetValues"]);
CRViewer1.ReportSource = ReportName;
CRViewer1.DisplayGroupTree = false;
use rptDoc.Refresh(); after loading report. i.e.
rptdoc.Load(ReportName);
rptDoc.Refresh();