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

after_create and before_create callbacks are not invoked inside a transaction? #202

Closed
abhinavsaxena opened this issue May 14, 2012 · 1 comment

Comments

@abhinavsaxena
Copy link

(*We are using stable build 1.0)
We are trying to use after_create callback to create other related db entries, but wish if any error in these entries could trigger a rollback. Here is my sample code:

class A extends ActiveRecord\Model{
   static $belongs_to = array(
    array('b')
  ); 
  static $after_create = array(
    'update_b'
  );  

  public function update_b() {
    $b = $this->b;
    if($b->update_attributes(array('foo' => 'bar')))
      return true;
    else
      throw new Exception("error in updating b");
  }

This does not seem to be working. Am I doing something wrong.

Similarly, I haven't been able to auto_save associated models ( has_many relationship)
for example

class C extends ActiveRecord\Model{
  static $has_one = array(
    array('d')
  );  


 static $before_create = array('build_default_d');

  protected function build_default_d() {
    $this->build_d();
  }
}

This in Ruby's ActiveRecord would have saved associated D as well on saving A, doesn't seem to be working here.

@greut
Copy link
Collaborator

greut commented May 14, 2012

For the nested models, check #187 (and #112) out.

About the callback, transaction stuff my advise would be to write a proper test against the nighty version if you can. Cheers.

Closing as you existing issues already exists and you're not using the latest version. Sorry pal.

@greut greut closed this as completed May 14, 2012
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

2 participants