I stand corrected. I thought the dependent option would only destroy the
employee record when the parent record is destroyed, such as the company or
person.
Happy to see this in my logs :)
Processing CompaniesController#update (for 127.0.0.1 at 2010-02-08 11:41:38)
[PUT]
Parameters: {"company"=>{"employees"=>""}, "page_path"=>"companies/edit",
"action"=>"update", "_method"=>"PUT",
"authenticity_token"=>"41Ga01quJfxLHN6SZCOTyQTDG7ihEurbqPzB143uYXk=",
"id"=>"76-chus-h-tel-dieu", "controller"=>"companies"}
User Load (0.8ms) SELECT * FROM "users" WHERE ("users"."id" = 1)
Company Load (0.8ms) SELECT * FROM "companies" WHERE ("companies"."id" =
76)
Employee Load (1.9ms) SELECT * FROM "employees" WHERE
("employees".company_id = 76)
SQL (1.7ms) BEGIN
Employee Destroy (0.5ms) DELETE FROM "employees" WHERE "id" = 84
SQL (1.1ms) COMMIT
Thanks a lot!
François
Le 2010-02-08 à 11:21, Bryan Larsen a écrit :
> I think I'm still missing something. You should be able to put the
> ":dependent => :destroy" on the join has_many, but leave it off of the
> has_many :through:
>
> has_many :employees, :accessible => true, :dependent => :destroy
> has_many :companies, :through => :employees, :order => :name
>
> Bryan
>
> François Beausoleil wrote:
>> Hi!
>> My parent models are plain old has_many (POHM ? :)). And no, I don't
>> want :dependent => :destroy. The company and person records are fine
>> as they are. It's the join model which I want destroyed, not
>> nullified.
>> class Person < AR::B
>> hobo_model
>> has_many :employees, :accessible => true
>> has_many :companies, :through => :employees, :order => "name"
>> end
>> class Company < AR::B
>> hobo_model
>> has_many :employees, :accessible => true
>> has_many :people, :through => :employees, :order => "name"
>> end
>> Thanks!
>> François
>> On 5 fév, 13:19, kevinpfromnm <[email protected]> wrote:
>>> Actually, doesn't sound like dependent destroy as he's talking about
>>> unlinking employee (join model) from person. Sounds like instead of
>>> unlinking, you actually want to destroy the join model, which from the
>>> view code you posted, that's what it should be doing. Unless you're
>>> talking about deleting the company record and not the employee record.
>>>
>>> Might be helpful to post the relevant associations of your Person and
>>> Company models as well.
>>>
>>> On Feb 4, 9:28 pm, Bryan Larsen <[email protected]> wrote:
>>>
>>>
>>>
>>>> You're looking for the :dependent => :destroy option to has_many, I
>>>> believe. That's part of Rails, not Hobo.
>>>> Bryan
>>>> Fran ois Beausoleil wrote:
>>>>> Hi all!
>>>>> I have an employee model like this:
>>>>> class Employee < ActiveRecord::Base
>>>>> hobo_model
>>>>> fields do
>>>>> timestamps
>>>>> end
>>>>> belongs_to :company
>>>>> belongs_to :person
>>>>> validates_uniqueness_of :person_id, :scope => :company_id
>>>>> end
>>>>> I'm on a Person page, where I have the has-many editor:
>>>>> <extend tag="form" for="Person">
>>>>> <old-form merge>
>>>>> <field-list: fields="name, employees">
>>>>> <employees-view:>
>>>>> <input-many>
>>>>> <field-list fields="company"/>
>>>>> </input-many>
>>>>> </employees-view:>
>>>>> </field-list:>
>>>>> </old-form>
>>>>> </extend>
>>>>> UI-wise, things work out: I can add / remove employee records. I'd
>>>>> like the association record to be destroyed when I unlink the employee
>>>>> from the person. How does that work?
>>>>> I read the source code, to see how it was implemented. I can't seem
>>>>> to find it at all:
>>>>> http://github.com/tablatom/hobo/blob/master/hobo/lib/hobo/accessible_...
>>>>> Thanks!
>>>>> Fran ois
>
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.