On Monday, March 27, 2017 at 7:45:43 PM UTC-7, Aryk Grosz wrote:
>
>
> http://edgeguides.rubyonrails.org/association_basics.html#options-for-has-one-dependent
>
> Is there an equivalent for this in SQL. Seems like the right place for 
> this would be in the AssociationDependencies plugin, but I dont see it 
> there.
>

In SQL, the equivalent would be a foreign key constraint.  So as long as 
you setup foreign keys correctly in your database, an exception will be 
raised if you try to delete a row referenced by an existing row.

If you want this to happen in Sequel::Model before a DELETE statement is 
sent to the database, you could do:

  def before_destroy
    cancel_action("still has associated objects") unless 
association_dataset.empty?
    super
  end

I suppose support for this could be added to the association_dependencies 
plugin, if someone wants to submit a patch with specs.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to