Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Filter by related fields #18

Closed
larylinz opened this issue Jun 26, 2014 · 6 comments
Closed

Filter by related fields #18

larylinz opened this issue Jun 26, 2014 · 6 comments

Comments

@larylinz
Copy link

Is there a way to implement filtering by related fields?
like: $filter->add('contact.lastname', 'name', 'text');
thxs.

@zofe
Copy link
Owner

zofe commented Jun 26, 2014

updated
hi, basically not for "all" fields and not for all kind of "relation", but can be done (for some).
see below

@zofe
Copy link
Owner

zofe commented Jun 26, 2014

it already works on belongsTo relations because internally it works on foreingKey:
see "Author" autocomplete: http://www.rapyd.com/rapyd-demo/filter
It filter by author_id, but using author.fullname as fieldname where:
"author" is the relation
"fullname" is a simple accessor (look one demo models)

to know how autocomplete works, if it's not intuitive, look on http://www.rapyd.com/rapyd-demo/advancedform

@zofe
Copy link
Owner

zofe commented Jun 27, 2014

ok now it should work also for:
hasOne, hasMany, belongsToMany

@larylinz
Copy link
Author

thxs! looks great! (changed to dev-master now)
got the filter and autocomplete now! :-)
but how to save realted fields? $edit->add('contact.lastname','name', 'text'); ?
it gives me the 'id' of the related row (like 'contact.id') and i'm able to change it, but i'd like to change for example 'lastname'.
how to do that?

@zofe
Copy link
Owner

zofe commented Jun 27, 2014

I'm working on that, but basically for now to store values:

  • it looks at relation-type first (so "contact."),
  • if relation is a "belongsTo" it try to store the foreign key value, ".field" is used only as display value
  • if relation is a "belongsToMany" it works on pivot table retrieving / storing associations, again ".field" is used only as display value
  • I plan to support "hasOne" too asap. (in this case it will store "lastname" value on contact table)

these samples are on demo / datafilter adv

@zofe
Copy link
Owner

zofe commented Jun 29, 2014

ok I close this issue because:

  • datafilter now can handle HasOne, HasMany, BelongsTo, BelongsToMany
  • field supported: text (HasOne, HasMany), select, radiogroup, autocomplete (BelongsTo), tags (BelongsToMany)

It's not all tested but feel free to open a new issue (but be specific: field-type relation-type).
Note: it works only for first level relationship. (you can't use 'relation.anotherrelation.field')

@zofe zofe closed this as completed Jun 29, 2014
zhwei added a commit to zhwei/rapyd-laravel that referenced this issue Jan 26, 2016
下划线split会出问题
philtweir pushed a commit to flaxandteal/rapyd-laravel that referenced this issue Aug 20, 2018
getOtherKey relation was removed from BelongsToMany (5.3 to 5.4), use Pivot instead...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants