Skip to content

Fix bug in fillable array#33

Closed
jpdunc23 wants to merge 1 commit intorainlab:masterfrom
jpdunc23:master
Closed

Fix bug in fillable array#33
jpdunc23 wants to merge 1 commit intorainlab:masterfrom
jpdunc23:master

Conversation

@jpdunc23
Copy link
Copy Markdown

This bug prevented the country_id and state_id fields from being
mass-assignable when updating a user.

This bug prevented the country_id and state_id fields from being
mass-assignable when updating a user.
@daftspunk
Copy link
Copy Markdown
Member

Hmm, not quite. October's Model is slightly different to Laravel, If you set the relation to the primary identifier, it will populate the relation. So for example:

$user->country = 3;

// Is the same as
$user->country = Country::find(3);

// And subsequently should set this attribute also
$user->country_id = 3;

If this is a bug, please provide some example code where it doesn't work.

@daftspunk daftspunk closed this Nov 21, 2014
@jpdunc23
Copy link
Copy Markdown
Author

I was trying to use the country_state partial of the account component on my front-end for users to update their account info (ended up using custom code for country and state dropdowns, as I think there might be an issue with the partial, or I'm using it wrong, see here: http://octobercms.com/forum/post/country-state-relation-doesnt-work-into-users-account-page). I followed the model you provide in the update partial. So something like this:

{{ form_ajax('onUpdate', { model: user }) }}

    <div class="form-group">
        <label for="accountName">Full Name</label>
        <input name="name" type="text" class="form-control" id="accountName" value="{{ form_value('name') }}">
    </div>

    <div class="form-group">
        <label for="accountEmail">Email</label>
        <input name="email" type="email" class="form-control" id="accountEmail" value="{{ form_value('email') }}">
    </div>

    <div class="form-group">
        <label for="accountPassword">New Password</label>
        <input name="password" type="password" class="form-control" id="accountPassword">
    </div>

    <div class="form-group">
        <label for="accountPasswordConfirm">Confirm New Password</label>
        <input name="password_confirmation" type="password" class="form-control" id="accountPasswordConfirm">
    </div>

    <div class="form-group">
        <label for="accountCountry">Country</label>
        <select name="country_id" id="accountCountry" class="form-control">
        {% for id, country in countries %}
            <option value="{{ id }}" {% if id == user.country_id %}selected{% endif %}>{{ country }}</option>
        {% endfor %}
        </select>
    </div>

    <button type="submit" class="btn btn-default">Save</button>

{{ form_close() }}

Before I changed country to country_id in the fillable array, that form would update everything but country_id in the database. The country_state partial also references country_id and state_id so I think it might have the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants