Skip to content

Instantly share code, notes, and snippets.

@brayann
Created November 26, 2012 01:56
Show Gist options
  • Save brayann/4146188 to your computer and use it in GitHub Desktop.
Save brayann/4146188 to your computer and use it in GitHub Desktop.
Diferença entre Rails x Laravel
Class User extends Eloquent {
public $acessible = array ('name', 'email');
public function posts () {
return $this->has_many('Post');
}
public function delete() {
Post::where_user_id($this->id)->delete();
parent::delete();
}
}
Class Post extends Eloquent {
public function user() {
return $this->belongs_to('User');
}
}
class User < ActiveRecord::Base
attr_accessible :name, :email
has_many :posts, :dependent => :destroy
end
class Post < ActiveRecord::Base
belongs_to :user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment