⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Extra fields in M:N tables



Kobus Myburgh

Kobus Myburgh
  • profile picture
  • Member

Posted 07 October 2012 - 15:24 PM

Hi guys,

Wow, I have to say that this is the greatest tool ever for me! The amount of time I have saved by implementing this is incredible!

I have a question, and am wondering on how to do the following:

Table: page (has 7 fields)
Table: box (has 5 fields)
Table: page_box (has 3 fields, namely page_id, box_id, position)

I have set up "Manage pages" and added a n_n relationship for the boxes, as follows:


$crud->set_table($this->config->item('db_prefix') . 'page');
$crud->set_relation_n_n('Boxes', $this->config->item('db_prefix') . 'page_box', $this->config->item('db_prefix') . 'box', 'page_id', 'box_id', 'title');


This works fine in the sense that I can assign boxes to the pages, but, for example, I would want the box position to change on a page basis, so, on the home page, the contact box must be in the second position, and on other pages, on the first position, therefore, I can not specify the position in the `box` table, but have to specify it in the `page_box` table. Is there a way to do this?

Thanks!

Kobus

Kobus Myburgh

Kobus Myburgh
  • profile picture
  • Member

Posted 17 October 2012 - 16:07 PM

Hi again,

Sorry to bother again - but has anyone seen this? Any advice? Here is a practical example of how I want to use it:

1. I have newsletters
2. I have subscribers
3. A subscriber can have the following status for each newsletter: "Subscribed", "Unsubscribed", "Blacklisted" or "Admin Blacklisted"

So, now, I need to have a way to choose a newsletter (as per #1 above), and the status thereof (as per #3 above) for a subscriber (as per #2 above). So, a single user may have only ONE of these options selected for a single newsletter, but could have subscriptions to many newsletters, for example:

1. Newsletter 1 - User 1 is UNSUBSCRIBED
2. Newsletter 2 - User 1 is SUBSCRIBED
3. Newsletter 3 - User 1 is BLACKLISTED
4. Newsletter 4 - User 1 is ADMIN BLACKLISTED

I hope this makes sense? Any help would be greatly appreciated.

Thanks

Kobus

jean-baptiste

jean-baptiste
  • profile picture
  • Member

Posted 07 November 2012 - 11:06 AM

Hello,
I have the same problem, all my relation tables for n-n relations have more than id and PRIORITY fields (for instance, my "author_book" table has also a "function" field) and I don't see a way to fill this field in the "author" form.

Kobus Myburgh

Kobus Myburgh
  • profile picture
  • Member

Posted 22 November 2012 - 14:49 PM

Hi, still having this problem after upgrading to version 1.3.3. Anyone has some insights into this? Thanks! :-)

victor

victor
  • profile picture
  • Member

Posted 22 November 2012 - 16:53 PM

[quote name='Kobus' timestamp='1349623486' post='3788']
Hi guys,

Wow, I have to say that this is the greatest tool ever for me! The amount of time I have saved by implementing this is incredible!

I have a question, and am wondering on how to do the following:

Table: page (has 7 fields)
Table: box (has 5 fields)
Table: page_box (has 3 fields, namely page_id, box_id, position)

I have set up "Manage pages" and added a n_n relationship for the boxes, as follows:


$crud->set_table($this->config->item('db_prefix') . 'page');
$crud->set_relation_n_n('Boxes', $this->config->item('db_prefix') . 'page_box', $this->config->item('db_prefix') . 'box', 'page_id', 'box_id', 'title');


This works fine in the sense that I can assign boxes to the pages, but, for example, I would want the box position to change on a page basis, so, on the home page, the contact box must be in the second position, and on other pages, on the first position, therefore, I can not specify the position in the `box` table, but have to specify it in the `page_box` table. Is there a way to do this?

Thanks!

Kobus
[/quote]

You can use "add_action" as solution

Kobus

Kobus
  • profile picture
  • Member

Posted 23 November 2012 - 16:29 PM

Hi Victor, I am sorry - not sure how add_action will achieve this? Could you explain a bit more, please?

victor

victor
  • profile picture
  • Member

Posted 24 November 2012 - 06:49 AM

I propose to change the box positions after adding basic data.

Your list:
page | boxes | positions
___________________________________
main | feedback , text | add_action_link

Kobus

Kobus
  • profile picture
  • Member

Posted 24 November 2012 - 15:10 PM

Hi Victor,

That makes sense. I wonder if I could pay you for developing this feature for me to actually make GroceryCRUD do this by default without the need for actions, and then I can donate it back to the community?

Thanks!

Kobus

victor

victor
  • profile picture
  • Member

Posted 24 November 2012 - 19:50 PM

I think that to use the "add_action" in this case is the most optimum way.
For example you have one field "position" which you need edit.
But for example other developer may have more fields
which them wants to edit.
And fields may have different types.
I have no idea how to organize it all in one page and that it was convenient.
Sorry, my English is poor.

Kobus

Kobus
  • profile picture
  • Member

Posted 25 November 2012 - 14:13 PM

Hi Victor,

Just as your English is poor, my Russian is poor - you never have to apologize :-) I know only one word in Russian, so I can not fault you - you are trying very well.

Thanks for your info - I think you may be right. Better to use actions. :-)

Regards,

Kobus

jean-baptiste

jean-baptiste
  • profile picture
  • Member

Posted 26 November 2012 - 10:25 AM

About the management of n-n relations with additional fields, I draw a suggestion for a new type of form field and it's behavior.

I could try to implement this fonctionality, but some tracks are welcomed. For instance, I suggest a way to edit a n-n relation table "participate". The "participate" table has five properties : id_author, id_paper, function and notes. By know, Grocerycrud proposes "set_relation_n_n" to display the n-n relation in the author view, but does not allow the edition of "function" and "notes". In my example, drawn in the attached file, the user chooses a paper (magazine) in a field and then a new line appears where he could edit the "function" and "notes" fields. I can't see any grocecrud method to invoque a callback after the user has chosen a new paper, but this has more to do with Ajax, as explained in Dynamically adding form inputs and submit using jQuery ?

Kobus

Kobus
  • profile picture
  • Member

Posted 26 November 2012 - 16:20 PM

Nice post, Jean-Baptiste. Not sure how to go about this yet, but it may be a good shift in the right direction. Thanks!