Ruby on Rails
Thursday, May 21, 2015
*changes to one association will not be reflected in the other until reload.
On Thu, May 21, 2015 at 6:14 PM, Stewart Mckinney <lordmaple@gmail.com> wrote:
Create two associations with conditions on the parent table with conditions that point to each "type" of address.For instance:has_many :addresseshas_one :primary_address,->() dowhere( :type => :primary )end,:class_name => AddressThis will make primary address accessible through addresses but also make it its own association ( so you can just pass that association to the form ).Be aware that changes to one association will not be reflected in the other. So if you change "primary_address", before you reload, the object in addresses which corresponds to your primary address will not have the changes you made to primary address. After you save/reload, they will.On Thu, May 21, 2015 at 6:00 PM, Walter Lee Davis <waltd@wdstudio.com> wrote:Do these addresses have any difference besides being primary or secondary? Are there extra fields in one that are not in the other? Or is primary maybe a boolean on the address object?
Walter
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/35D23682-9E4B-4B3D-A985-FB12B485C269%40wdstudio.com.
On May 21, 2015, at 3:36 PM, Elizabeth McGurty <emcgurty2@gmail.com> wrote:
> I have a parent table. And associated with that parent table is two possible addresses, a primary one and/or an alternative: (has_many and accepts_nested_attributes_for).
>
> Rather than creating a second addresses table, I have used a flag, address_type to distinguish primary from alternative, which will apparently only be useful if I can create a condition on fields_for
>
> But now as I explore and research more, seems that I cannot create a condition on fields_for addresses, type => 'alternative' or 'primary'.
>
> I want to utilize Rails associations... Should I just create tables: primary_addresses and alternative_addresses?
>
> Thanks,
>
> Liz
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ae5620b7-a237-4ba2-ac52-1596fa3b7d8a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CA%2BCQ937oq%3DBOx80eSnnqTxaYwid7D%2BaNzA6_m%2BQUi2vFWSi-JA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment