⚠ 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

Multiple relations?



jonathanw
  • profile picture
  • Member

Posted 13 April 2015 - 17:26 PM

Hi,

 

I'm using groceryCRUD for file routing purposes.

My database looks like this

 

parties // just basic information about parties in the system

  id

  orgno

  name

 

flows // this table connects parties

  id

  sender (fk to parties.id)

  receiver (fk to parties.id)

  direction

 

Ie, one party in the system sends to another, in a specified direction.

 

Now, I'm trying to add enveloping to the routed files (the user is configuring one envelope per flow);

 

envelope

  id

  flow_id (fk to flows.id)

  sender

  sender_type

  receiver

  receiver_type

 

Now - here comes the problem. How the heck do I get this to work in groceryCRUD?

I wanted to get the flow name, ie "Sender -> Receiver (Direction)" which works if I do a SQL query. But can it be done with set_relation or _n_n?

I've tried so many different variations, but still doesn't get it right.

 

The most important thing is to get the flow name for the dropdown when adding new envelopes, instead of having to input a flow_id. That would of course work - but is not user friendly.

 

Any tips?


jonathanw
  • profile picture
  • Member

Posted 16 April 2015 - 11:32 AM

Hmm...

 

I'm getting somewhere atleast.

If I do like this:

 

$crud->set_relation('flow_id','flows','{sender} -> {receiver} ({direction})');

 

I atleast get some result, but only with ID:s.

The view looks like "195 -> 234 (IN)".

Now I need to translate 195 and 234 with the names from the parties table.

 

How do I do this?

 

As far as I can understand by set_relation_n_n, it can only get one field at a time. I've tried

$crud->set_relation_n_n('flow_id','flows','parties','id','sender','name');

but without succes. This of course translates the sender correctly, but not the receiver.

And the whole point being to have {sender} -> {receiver} ({direction}) is therefore lost.

 

Anyone who can help me?


jonathanw
  • profile picture
  • Member

Posted 16 April 2015 - 15:47 PM

Solved it by using callbacks!

One that gets the current flow name (for viewing) and one that just list all available flows and their ID (this is used for add/edit operation).

 

If you want to see the code, reply here :)