Forums

Update field belongsTo

webcrea 19 May, 2015
Hello... (Bob ;-)

To update a field from a table with BelongsTo relation

Comprofiler->Users

I do that in edit
<p>Name : <input type="text" name="Users[name]" id="Users[name]" value="{Users.name}"> <br />Username :<input type="text" name="Users[username]" id="Users[username]" value="{Users.username}"></p>
<p>Awards obtained : <input type="text" name="Users.Comprofiler[cb_awards_obtained_dyn]" id="Users.Comprofiler[cb_awards_obtained_dyn]" value="<?php echo $row['Comprofiler']['cb_awards_obtained_dyn']; ?>">


For Users.Comprofiler[cb_awards_obtained_dyn]
I try
Comprofiler[cb_awards_obtained_dyn]
Users[cb_awards_obtained_dyn]
Users[Comprofiler][cb_awards_obtained_dyn]
..etc


but the cb_awards_obtained_dyn is never update

do you have an idea, maybe ?
Must we include an hidden input with the Comprofiler id?

thanks
best regards
chris
GreyHead 25 May, 2015
Hi chris,

It's not clear to me what this code is or where you are using it in CC?

If you want to update a record then you do need to have a record identifier.

Bob
webcrea 02 Jun, 2015
Hello Bob,
In CC I start from "users" table. I add a model "Comprofiler" with a belongsTo relation. the foreign key is id
(in community builder, id is the same as user id)
Associated save is on Yes

In Front list / Action / Edit there is the form with a hidden field id (the record identifier ?)

<h1>User Edit</h1>
<h2>Username : {Users.username}</h2>
<p>Name : <input type="text" name="Users[name]" id="Users[name]" value="{Users.name}"> </p>
<p>Awards obtained : <input type="text" name="Users.Comprofiler[cb_awards_obtained_dyn]" id="Users.Comprofiler[cb_awards_obtained_dyn]" value="<?php echo $row['Comprofiler']['cb_awards_obtained_dyn']; ?>">
<input type="hidden" name="Users[id]" /> <input type="submit" class="button" value="Save" />
This topic is locked and no more replies can be posted.