Created
November 26, 2012 01:56
-
-
Save brayann/4146188 to your computer and use it in GitHub Desktop.
Diferença entre Rails x Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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