Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Support for nested attributes #112

Open
Morpheu5 opened this issue Jan 6, 2011 · 2 comments · May be fixed by #187
Open

[feature] Support for nested attributes #112

Morpheu5 opened this issue Jan 6, 2011 · 2 comments · May be fixed by #187
Labels

Comments

@Morpheu5
Copy link

Morpheu5 commented Jan 6, 2011

Follow up from https://github.com/kla/php-activerecord/issues/issue/111, see also http://www.phpactiverecord.org/boards/1/topics/309

It would be useful to be able to build forms for nested attributes, and using the posted array to update the model and its associated models all at once.

For example, consider an Invoice model that has many Items. The form would send back something like

invoice[id] = 42
invoice[description] = Lorem ipsum dolor
invoice[paid] = 1
invoice[items_attributes][0][description] = First item
invoice[items_attributes][0][price] = 100
invoice[items_attributes][1][description] = Second item
invoice[items_attributes][1][price] = 250

and so on. Then, in Rails, you'd do something like

def update
    invoice = Invoice.find(params[:id]) # the id comes from the URL, not from the form
    invoice.update_attributes(params[:invoice]) # and this is the array that comes from the form
end

and the ActiveRecord::Base component (educated guess) takes care of updating the model's attributes and any relevant associated object.

@miklschmidt
Copy link

Actually i am currently working on this, in a seperate class layer above phpactiverecord and a function called from_post(). It's already semi functional, if my boss allows it, i'll modify it to fit this description and submit a pull request.

@miklschmidt
Copy link

#187 There we are :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants