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

Cached association #434

Open
markmcdonald51 opened this issue Jun 26, 2015 · 4 comments
Open

Cached association #434

markmcdonald51 opened this issue Jun 26, 2015 · 4 comments

Comments

@markmcdonald51
Copy link

Hi,

I noticed an interesting thing happens when I use an association that uses a through: association on the reverse association.

So for example, I have models for company and shareholder and a join table in between called company_shareholders that contains the company_id and shareholder_id.... I made a has_many shareholders, through: :company_shareholders and a has_many :companies, through: :company_shareholders in their reverse association.

The interesting thing is when it is rendered it sometimes will show the correct fields, meaning it excludes company in the company edit/add and excludes shareholders in the shareholder forms... But eventually it will get catched and then be missing either of the associations, which makes the form invalid in this case.

For a simple fix, I have just included it in only one controller (the companies cntlr) but it would be super nice if it would work in both as it is a much simpler way to edit.

I should tell you that I am also using the form_ui :chosen for both of the associations.

If this isn't fixable or it is just the way rails caches it's ok. Just wanted to report this as I have not found a way to fix it mingling in the controller code.

Thanks in advance.
Mark

@markmcdonald51
Copy link
Author

What is really strange is that both associations render perfect until I submit the form on either... then the opposite association no longer has the one is now missing the others form for that association... Hope this makes sense.

class ShareholderRelationship < ActiveRecord::Base
belongs_to :company
belongs_to :shareholder
end

@scambra
Copy link
Member

scambra commented Jul 31, 2015

If you can create a sample app to reproduce it, it would easier to debug it by me

@david0315
Copy link

david0315 commented Sep 5, 2016

config.columns[:appliance_id].form_ui = :select
config.columns[:appliance_id].options = {options: (RecyclingAppliance.all.map{|p| [p.title, p.id]})}
Also encountered the same problem I do not know where to disable the cache

@scambra
Copy link
Member

scambra commented Sep 5, 2016

@lklkdawei your problem seems different, at least @markmcdonald51 didn't say he were setting options in controller. If you set options in that way, they will be loaded when app starts, not on every request.

You should use applicance column if appliance is a belongs_to association, set form_ui to :select, and ActiveScaffold will load all recycling appliance (your association must be belongs_to :appliance, class_name: 'RecyclingAppliance'). If you want to filter some records from select, you can define options_for_association_conditions or association_klass_scoped in your helper: https://github.com/activescaffold/active_scaffold/wiki/Custom-Association-Options

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

No branches or pull requests

3 participants