Closed delafred closed 5 years ago
Hey there @delafred
It seems there's a bit of misconception here.
I guess you have a table named langue
which contains at least 2 columns, id
and something else (in which you have 'fr', 'en', and so on).
If everything is correct, your table utilisateur
contains a column langue_id
but no column langue
.
Now, when you set that language for a user you are actually linking the langue
bean to the utilisateur
bean, and there's 2 way of doing this.
Either you use the id of the langue
:
$ta = R::load( 'utilisateur', 1 );
$ta->langue_id = 4;
R::store( $ta );
Or you use the langue
bean:
$ta = R::load( 'utilisateur', 1 );
$fr = R::load( 'langue', 4 );
$ta->langue = $fr;
R::store( $ta );
In the second case, Redbean will extract the id from that bean and set it to the column langue_id
of your utilisateur
table.
Let me now if that wasn't clear and I will explain myself in french for you.
TL;DR
You cannot have a column named xxx
and a column named xxx_id
on the same table since it points to the exact same thing for RedBean: the xxx
bean.
Thanks for your answer, will try to continue in English for the community
You cannot have a column named xxx and a column named xxx_id on the same table since it points to the exact same thing for RedBean: the xxx bean.
This is the unpredicted behaviour that I have discovered and not a model conception error (even if it can be strange from outside to see those 2 fields on the same table). Is it a convention like "restricted naming" or is it a bug ?
I fully undestand the need of convention and it's one of the powerfull of this ORM. Is there a way I can help to define and put on website "actual conventions" as I didn't find any uptodate doc on this ?
https://redbeanphp.com/manual3_0/index.php?p=/manual3_0/schema is obsolete https://www.redbeanphp.com/index.php?p=/crud seem incomplete
Tables naming:
Fields naming:
I guess that's the most you can find: https://www.redbeanphp.com/index.php?p=/many_to_one
I agree that a list of Redbean's convention in a page (named ie. "Conventions") would be a nice addition @gabordemooij
Okay, I will add it to https://www.redbeanphp.com/index.php?p=/crud and turn it into a list. Thanks for reporting!
Since this is a shortcoming in the manual this will count as a bug. I tagged this issue as a bug.
@gabordemooij I feel like this is ok for now. Maybe we can talk about it again when the manual is available on github for edition ? ;)
yes, I have made steps towards that
It seem that redbean missread informations between "langue_id" and "langue"
If I quote line with "$ta->langue" it work if I quote line with "$ta->langue_id" it still not work
Reproduced on RB 5.0 & 5.3 MySQL 5.6 // PHP 7.2
Any idea ?