0

I am using PHP with Flourish. I read their documentation here and here. Let's suppose I have a table persons and another table items. Let's suppose further that I have an item_id1 and an item_id2 in the persons table. Both of them are foreign keys to the items table. I would like to get a record from the items table based on the relation between persons and items based on the item_id2 foreign key.

If I am not mistaken this could be achieved with

$person->createItem()

if $person is the fActiveRecord generated from a record of the persons table in most of the cases. But in this particular case, when multiple foreign keys point to the very same table. This is understandable, because Flourish is not able to determine which relation should be used if we do not give it at least a route.

So, if we want to get the record from the items table which corresponds to the item_id2 foreign key, then we should give the route as parameter. I didn't see a description or an example in their documentation which addresses this particular problem, so my question is:

How should we tell createItem that I want to use the item_id2 key?

$person->createItem("item_id2")

does not work.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175

1 Answers1

0

You are right, your example should work. I just checked and I can tell that it works for me. The only difference I can spot between your example and the documentation is, that you are using double quotes. Try single quotes.

$person->createItem('item_id2')

I think that might be all it takes to make it work.

Blue Box
  • 318
  • 2
  • 8
  • I do not believe that there is a difference between single and double quotes. They are both string representation in PHP. Why should simple quotes be better in this case? – Lajos Arpad Feb 08 '14 at 03:56
  • I have to admit that I don't analyse this problem from an academic point of view. What I did is: I use the same function, it works for me and the only difference between your code and mine is the quotes. – Blue Box Feb 13 '14 at 16:03
  • But that does not make a difference, see the php documentation. – Lajos Arpad Feb 13 '14 at 18:32