$user = Model_User::find_by_id(Session::get('user_id')); $tool = Model_Tool::find_by_id($id); $user->tools = $tool; $user->save();
$tool = Model_Tool::find_by_id($id); ... $tool->languages->order_by('date', 'desc')->get_one(); For the moment I use this probably bad method
$lang = Model_Language::query() ->where('tool_id', $tool->id) ->order_by('date', 'desc') ->get_one();thanks edit: wow ??? <code> doesn't work
$users = Model_User::find()->related('tool_users')->related('tool_users.tool')->get();
Easy: fetch the relationship and delete the ID of the relation you want removed from the array. Example:- I'm currently trying Fuel and don't find anyway to delete a many to many relation ? I have a model user with a many to many relation to tool model
$user = Model_User::query()->related('articles')->where('id', 1)->get_one(); unset($user->articles[5]); // removes relationship with article with ID 5 $user->save();
- Then, maybe an issue but you can add the same relation twice or more time ?! Strange Tried with this code, executed many times with the same tool idHave you tried it or are you just assuming without checking? The Orm will detect the relation is already there and won't save it a second time. Shouldn't even be possible btw, best way of setting up the in-between table is to have both the foreign-keys combined set as PK.
How can I fetch easily a extra colum on users_tools table ?It will always fetch all columns, picking which column to fetch and not to fetch isn't possible yet. Will probably be in Fuel 1.1.
You can only add conditions with eager loading, there's nothing bad about eager loading btw - if you're sure you're going to need the relation it will be far more efficient in most cases.I want to fetch the first related objects ordered by a column for a loaded object like
Ok thanks for the reply. I'll test all of it but yes, I tried to setting up the same relation manytimes and yes it worksJelmer Schreuder wrote on Tuesday 21st of June 2011:Easy: fetch the relationship and delete the ID of the relation you want removed from the array. Example:- I'm currently trying Fuel and don't find anyway to delete a many to many relation ? I have a model user with a many to many relation to tool model$user = Model_User::query()->related('articles')->where('id', 1)->get_one(); unset($user->articles[5]); // removes relationship with article with ID 5 $user->save();- Then, maybe an issue but you can add the same relation twice or more time ?! Strange Tried with this code, executed many times with the same tool idHave you tried it or are you just assuming without checking? The Orm will detect the relation is already there and won't save it a second time. Shouldn't even be possible btw, best way of setting up the in-between table is to have both the foreign-keys combined set as PK.
How can I fetch easily a extra colum on users_tools table ?It will always fetch all columns, picking which column to fetch and not to fetch isn't possible yet. Will probably be in Fuel 1.1.
You can only add conditions with eager loading, there's nothing bad about eager loading btw - if you're sure you're going to need the relation it will be far more efficient in most cases.I want to fetch the first related objects ordered by a column for a loaded object like
It looks like you're new here. If you want to get involved, click one of these buttons!