So, the reason why I'm confused is because I'm a PHP developer and used Laravel and FuelPHP alot
What I really don't understand is his association.
What I mean, I wanted to create the hasOne / BelongsTo core logic with the following
User has one profile.
User owned profile
I'm used to the next creation (Laravel style)
User table
id | username | email | password
---------------------------------------
1 | My Username | My email | 1234568
Users_profile table
user_id | first_name | last_name
----------------------------------------
1 | My First name | My Last name
Then I just defined the models this way
User model
class Users extends Eloquent
{
public function profile()
{
return $this->hasOne('profile');
}
}
Profile model
class Profile extends Eloquent
{
protected $tableName = 'users_profile';
protected $primaryKey = 'user_id';
public function user()
{
return $this->belongsTo('User');
}
}
And it just works because it return $this->hasOne('profile');will automatically checkuser_id
Tried the same thing in Sails.js (in sails)
User model
module.exports = {
attributes: {
username: {
type: 'string',
unique: true,
required: true
},
email: {
type: 'string',
unique: true,
email: true,
required: true
},
password: {
type: 'string',
required: true
},
profile: {
model: "profile",
}
},
};
Profile model
module.exports = {
tableName: 'user_profile',
autoPK: false,
autoCreatedAt: false,
autoUpdateddAt: false,
attributes: {
user_id: {
type: 'integer',
primaryKey: true
},
first_name: {
type: 'string',
},
last_name: {
type: 'string',
},
user: {
model: "user"
}
}
};
And now from the documentation I have to update the table this way
id | username | email | password | profile
-------------------------------------------------
1 | My Username | My email | 1234568 | 1
user_id | first_name | last_name | user |
-----------------------------------------------
1 | My First name | My Last name | 1
So, I need to save 2 more identifiers again, and I really don't understand why.
, via, (, )
, - ?
( ), , , , ( )